Skip to content

Commit

Permalink
Release v1.15.0
Browse files Browse the repository at this point in the history
- Add regular expression functions.
    - REGEXP_MATCH
    - REGEXP_FIND
    - REGEXP_FIND_SUBMATCHES
    - REGEXP_FIND_ALL
    - REGEXP_REPLACE
- Add Table-Valued functions.
    - CSV_INLINE
    - JSON_INLINE
  • Loading branch information
mithrandie committed Mar 28, 2021
2 parents 53fa2a6 + b3b71cd commit 7b43dce
Show file tree
Hide file tree
Showing 25 changed files with 3,138 additions and 1,975 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Change Log

## Version 1.15.0

Released on March 28, 2021

- Add regular expression functions.
- REGEXP_MATCH
- REGEXP_FIND
- REGEXP_FIND_SUBMATCHES
- REGEXP_FIND_ALL
- REGEXP_REPLACE
- Add Table-Valued functions.
- CSV_INLINE
- JSON_INLINE

## Version 1.14.1

Released on March 21, 2021
Expand Down
32 changes: 18 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ifneq ($(shell command -v git && git remote -v 2>/dev/null | grep mithrandie/csv
endif

ifdef VERSION
LDFLAGS := -ldflags="-X github.com/mithrandie/csvq/lib/query.Version=$(VERSION) -s -w -buildid="
LDFLAGS := -ldflags="-X github.com/mithrandie/csvq/lib/query.Version=$(VERSION) -s -w"
endif

DIST_DIRS := find * -type d -exec
Expand All @@ -19,7 +19,7 @@ $(BINARY): build

.PHONY: build
build:
go build $(LDFLAGS) -o $(GOPATH)/bin/$(BINARY)
go build -trimpath $(LDFLAGS) -o $(GOPATH)/bin/

.PHONY: install
install:
Expand All @@ -29,21 +29,25 @@ install:
clean:
go clean -i -cache -modcache

.PHONY: install-gox
install-gox:
ifeq ($(shell command -v gox 2>/dev/null),)
go get github.com/mitchellh/gox
endif

.PHONY: build-all
build-all: install-gox
gox $(LDFLAGS) --osarch="$(RELEASE_ARCH)" -output="dist/${BINARY}-${VERSION}-{{.OS}}-{{.Arch}}/{{.Dir}}"
build-all:
IFS='/'; \
for TARGET in $(RELEASE_ARCH); \
do \
set -- $$TARGET; \
GOOS=$$1 GOARCH=$$2 go build -trimpath $(LDFLAGS) -o "dist/$(BINARY)-$(VERSION)-$${1}-$${2}/"; \
done

.PHONY: build-pre-release
build-pre-release: install-gox
gox $(LDFLAGS) --osarch="$(PRERELEASE_ARCH)" -output="dist/${BINARY}-${VERSION}-{{.OS}}-{{.Arch}}/{{.Dir}}"

.PHONY: dist
build-pre-release:
IFS='/'; \
for TARGET in $(PRERELEASE_ARCH); \
do \
set -- $$TARGET; \
GOOS=$$1 GOARCH=$$2 go build -trimpath $(LDFLAGS) -o "dist/$(BINARY)-$(VERSION)-$${1}-$${2}/"; \
done

.PHONY: dist -
dist:
cd dist && \
$(DIST_DIRS) cp ../LICENSE {} \; && \
Expand Down
26 changes: 18 additions & 8 deletions docs/_posts/2006-01-02-select-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,15 @@ table
table_entity
: table_identifier
| table_object
| json_inline_table
| inline_table_object

table_identifier
: table_name
| STDIN

inline_table_identifier
: table_name
| url

laterable_table
: subquery
Expand Down Expand Up @@ -150,9 +154,11 @@ table_object
| JSON(json_query, table_identifier)
| LTSV(table_identifier [, encoding [, without_null]])

json_inline_table
: JSON_TABLE(json_query, json_file)
| JSON_TABLE(json_query, json_data)
inline_table_object
: CSV_INLINE(delimiter, inline_table_identifier [, encoding [, no_header [, without_null]]])
| CSV_INLINE(delimiter, csv_data)
| JSON_INLINE(json_query, inline_table_identifier [, encoding [, no_header [, without_null]]])
| JSON_INLINE(json_query, json_data)

```

Expand All @@ -175,6 +181,11 @@ _table_name_

Once a file is loaded, then the data is cached and it can be loaded with only file name after that within the transaction.

_url_
: [identifier]({{ '/reference/statement.html#parsing' | relative_url }})

A URL of the http or https scheme to refer to a resource.

_alias_
: [identifier]({{ '/reference/statement.html#parsing' | relative_url }})

Expand Down Expand Up @@ -208,6 +219,9 @@ _json_file_

If a file name extension is ".json", you can omit it.

_csv_data_
: [string]({{ '/reference/value.html#string' | relative_url }})

_json_data_
: [string]({{ '/reference/value.html#string' | relative_url }})

Expand All @@ -230,10 +244,6 @@ _no_header_
_without_null_
: [boolean]({{ '/reference/value.html#boolean' | relative_url }})

> A Table Object Expression for JSON loads data from JSON file, and you can operate the data.
> A JSON Table Expression can load data from JSON file as well, but the result is treated as a inline table, so you can only refer the result within the query.


#### Special Tables
{: #special_tables}

Expand Down
4 changes: 2 additions & 2 deletions docs/_posts/2006-01-02-statement.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ SELECT @id := @id + 1 AS id, -- Line Comment

ABSOLUTE ADD AFTER AGGREGATE ALTER ALL AND ANY AS ASC AVG
BEFORE BEGIN BETWEEN BREAK BY
CASE CHDIR CLOSE COMMIT CONTINUE COUNT CREATE CROSS CUME_DIST CURRENT CURSOR
CASE CHDIR CLOSE COMMIT CONTINUE COUNT CREATE CROSS CSV_INLINE CUME_DIST CURRENT CURSOR
DECLARE DEFAULT DELETE DENSE_RANK DESC DISPOSE DISTINCT DO DROP DUAL
ECHO ELSE ELSEIF END EXCEPT EXECUTE EXISTS EXIT
FALSE FETCH FIRST FIRST_VALUE FOLLOWING FOR FROM FULL FUNCTION
GROUP
HAVING
IF IGNORE IN INNER INSERT INTERSECT INTO IS
JOIN JSON_AGG JSON_OBJECT JSON_ROW JSON_TABLE
JOIN JSON_AGG JSON_INLINE JSON_OBJECT JSON_ROW JSON_TABLE
LAG LAST LAST_VALUE LATERAL LEAD LEFT LIKE LIMIT LISTAGG
MAX MEDIAN MIN
NATURAL NEXT NOT NTH_VALUE NTILE NULL
Expand Down
206 changes: 206 additions & 0 deletions docs/_posts/2006-01-02-string-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ category: reference
| [INSTR](#instr) | Return the index of the first occurrence of a substring |
| [LIST_ELEM](#list_elem) | Return a element of a list |
| [REPLACE](#replace) | Return a string replaced the substrings with another string |
| [REGEXP_MATCH](#regexp_match) | Verify a string matches with a regular expression |
| [REGEXP_FIND](#regexp_find) | Return a string that matches a regular expression |
| [REGEXP_FIND_SUBMATCHES](#regexp_find_submatches) | Return a string representing an array that matches a regular expression |
| [REGEXP_FIND_ALL](#regexp_all) | Return a string representing a nested array that matches a regular expression |
| [REGEXP_REPLACE](#regexp_replace) | Return a string replaced substrings that match a regular expression with another strings |
| [FORMAT](#format) | Return a formatted string |
| [JSON_VALUE](#json_value) | Return a value from json |
| [JSON_OBJECT](#json_object) | Return a string formatted in json object |
Expand Down Expand Up @@ -439,6 +444,197 @@ _return_

Returns the string that is replaced all occurrences of _old_ with _new_ in _str_.

### REGEXP_MATCH
{: #regexp_match}

```
REGEXP_MATCH(str, regexp [, flags])
```

_str_
: [string]({{ '/reference/value.html#string' | relative_url }})

_regexp_
: [string]({{ '/reference/value.html#string' | relative_url }})

_flags_
: [string]({{ '/reference/value.html#string' | relative_url }})

A string including the [flags of regular expressions](#flags-of-regular-expressions)

_return_
: [ternary]({{ '/reference/value.html#ternary' | relative_url }})

Verifies the string _str_ matches with the regular expression _regexp_.

### REGEXP_FIND
{: #regexp_find}

```
REGEXP_FIND(str, regexp [, flags])
```

_str_
: [string]({{ '/reference/value.html#string' | relative_url }})

_regexp_
: [string]({{ '/reference/value.html#string' | relative_url }})

_flags_
: [string]({{ '/reference/value.html#string' | relative_url }})

A string including the [flags of regular expressions](#flags-of-regular-expressions)

_return_
: [string]({{ '/reference/value.html#string' | relative_url }})

Returns the string that matches the regular expression _regexp_ in _str_.

#### Examples

```shell
# Return the matched string.
$ csvq "SELECT REGEXP_FIND('ABCDEFG abcdefg', 'cdef')"
+----------------------------------------+
| REGEXP_FIND('ABCDEFG abcdefg', 'cdef') |
+----------------------------------------+
| cdef |
+----------------------------------------+

# Return the submatched string if there is a submatch expression.
$ csvq "SELECT REGEXP_FIND('ABCDEFG abcdefg', 'c(de)f')"
+------------------------------------------+
| REGEXP_FIND('ABCDEFG abcdefg', 'c(de)f') |
+------------------------------------------+
| de |
+------------------------------------------+

# Return the first matched string if there are multiple matched strings.
$ csvq "SELECT REGEXP_FIND('ABCDEFG abcdefg', 'cdef', 'i')"
+---------------------------------------------+
| REGEXP_FIND('ABCDEFG abcdefg', 'cdef', 'i') |
+---------------------------------------------+
| CDEF |
+---------------------------------------------+
```

### REGEXP_FIND_SUBMATCHES
{: #regexp_find_submatches}

```
REGEXP_FIND_SUBMATCHES(str, regexp [, flags])
```

_str_
: [string]({{ '/reference/value.html#string' | relative_url }})

_regexp_
: [string]({{ '/reference/value.html#string' | relative_url }})

_flags_
: [string]({{ '/reference/value.html#string' | relative_url }})

A string including the [flags of regular expressions](#flags-of-regular-expressions)

_return_
: [string]({{ '/reference/value.html#string' | relative_url }})

A string representing a JSON array.

Returns the string representing an array that matches the regular expression _regexp_ in _str_.

#### Examples

```shell
# Return all the first matched strings including submatches.
$ csvq "SELECT REGEXP_FIND_SUBMATCHES('ABCDEFG abcdefg', 'c(de)f', 'i')"
+----------------------------------------------------------+
| REGEXP_FIND_SUBMATCHES('ABCDEFG abcdefg', 'c(de)f', 'i') |
+----------------------------------------------------------+
| ["CDEF","DE"] |
+----------------------------------------------------------+

# Return only the submatched string.
$ csvq "SELECT JSON_VALUE('[1]', REGEXP_FIND_SUBMATCHES('ABCDEFG abcdefg', 'c(de)f', 'i'))"
+-----------------------------------------------------------------------------+
| JSON_VALUE('[1]', REGEXP_FIND_SUBMATCHES('ABCDEFG abcdefg', 'c(de)f', 'i')) |
+-----------------------------------------------------------------------------+
| DE |
+-----------------------------------------------------------------------------+
```

### REGEXP_FIND_ALL
{: #regexp_all}

```
REGEXP_FIND_ALL(str, regexp [, flags])
```

_str_
: [string]({{ '/reference/value.html#string' | relative_url }})

_regexp_
: [string]({{ '/reference/value.html#string' | relative_url }})

_flags_
: [string]({{ '/reference/value.html#string' | relative_url }})

A string including the [flags of regular expressions](#flags-of-regular-expressions)

_return_
: [string]({{ '/reference/value.html#string' | relative_url }})

A string representing a nested JSON array.

Returns the string representing a nested array that matches the regular expression _regexp_ in _str_.

#### Examples

```shell
# Return all the matched strings.
$ csvq "SELECT REGEXP_FIND_ALL('ABCDEFG abcdefg', 'c(de)f', 'i')"
+---------------------------------------------------+
| REGEXP_FIND_ALL('ABCDEFG abcdefg', 'c(de)f', 'i') |
+---------------------------------------------------+
| [["CDEF","DE"],["cdef","de"]] |
+---------------------------------------------------+

# Return only submatched strings as an array.
$ csvq "SELECT JSON_VALUE('[][1]', REGEXP_FIND_ALL('ABCDEFG abcdefg', 'c(de)f', 'i'))"
+------------------------------------------------------------------------+
| JSON_VALUE('[][1]', REGEXP_FIND_ALL('ABCDEFG abcdefg', 'c(de)f', 'i')) |
+------------------------------------------------------------------------+
| ["DE","de"] |
+------------------------------------------------------------------------+
```

### REGEXP_REPLACE
{: #regexp_replace}

```
REGEXP_REPLACE(str, regexp, replacement_value [, flags])
```

_str_
: [string]({{ '/reference/value.html#string' | relative_url }})

_regexp_
: [string]({{ '/reference/value.html#string' | relative_url }})

_replacement_value_
: [string]({{ '/reference/value.html#string' | relative_url }})

_flags_
: [string]({{ '/reference/value.html#string' | relative_url }})

A string including the [flags of regular expressions](#flags-of-regular-expressions)

_return_
: [string]({{ '/reference/value.html#string' | relative_url }})


Returns the string replaced substrings that match the regular expression _regexp_ with _replacement_value_ in _str_.

### FORMAT
{: #format}

Expand Down Expand Up @@ -555,3 +751,13 @@ _return_
Returns a string formatted in JSON.

If no arguments are passed, then the object include all fields in the view.

## Flags of regular expressions
{: #flags-of-regular-expressions}

| flag | description |
|:-|:-|
| i | case-insensitive |
| m | multi-line mode |
| s | let . match \n |
| U | swap meaning of x* and x*?, x+ and x+?, etc. |
Loading

0 comments on commit 7b43dce

Please sign in to comment.