mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #60881 from ClickHouse/add-docs-to-simplejson-and-sin
Add docs to simplejson and sin
This commit is contained in:
commit
cccf054420
@ -5,80 +5,372 @@ sidebar_label: JSON
|
||||
---
|
||||
|
||||
There are two sets of functions to parse JSON.
|
||||
- `visitParam*` (`simpleJSON*`) is made to parse a special very limited subset of a JSON, but these functions are extremely fast.
|
||||
- `simpleJSON*` (`visitParam*`) is made to parse a special very limited subset of a JSON, but these functions are extremely fast.
|
||||
- `JSONExtract*` is made to parse normal JSON.
|
||||
|
||||
# visitParam functions
|
||||
# simpleJSON/visitParam functions
|
||||
|
||||
ClickHouse has special functions for working with simplified JSON. All these JSON functions are based on strong assumptions about what the JSON can be, but they try to do as little as possible to get the job done.
|
||||
|
||||
The following assumptions are made:
|
||||
|
||||
1. The field name (function argument) must be a constant.
|
||||
2. The field name is somehow canonically encoded in JSON. For example: `visitParamHas('{"abc":"def"}', 'abc') = 1`, but `visitParamHas('{"\\u0061\\u0062\\u0063":"def"}', 'abc') = 0`
|
||||
2. The field name is somehow canonically encoded in JSON. For example: `simpleJSONHas('{"abc":"def"}', 'abc') = 1`, but `simpleJSONHas('{"\\u0061\\u0062\\u0063":"def"}', 'abc') = 0`
|
||||
3. Fields are searched for on any nesting level, indiscriminately. If there are multiple matching fields, the first occurrence is used.
|
||||
4. The JSON does not have space characters outside of string literals.
|
||||
|
||||
## visitParamHas(params, name)
|
||||
## simpleJSONHas
|
||||
|
||||
Checks whether there is a field with the `name` name.
|
||||
Checks whether there is a field named `field_name`. The result is `UInt8`.
|
||||
|
||||
Alias: `simpleJSONHas`.
|
||||
**Syntax**
|
||||
|
||||
## visitParamExtractUInt(params, name)
|
||||
|
||||
Parses UInt64 from the value of the field named `name`. If this is a string field, it tries to parse a number from the beginning of the string. If the field does not exist, or it exists but does not contain a number, it returns 0.
|
||||
|
||||
Alias: `simpleJSONExtractUInt`.
|
||||
|
||||
## visitParamExtractInt(params, name)
|
||||
|
||||
The same as for Int64.
|
||||
|
||||
Alias: `simpleJSONExtractInt`.
|
||||
|
||||
## visitParamExtractFloat(params, name)
|
||||
|
||||
The same as for Float64.
|
||||
|
||||
Alias: `simpleJSONExtractFloat`.
|
||||
|
||||
## visitParamExtractBool(params, name)
|
||||
|
||||
Parses a true/false value. The result is UInt8.
|
||||
|
||||
Alias: `simpleJSONExtractBool`.
|
||||
|
||||
## visitParamExtractRaw(params, name)
|
||||
|
||||
Returns the value of a field, including separators.
|
||||
|
||||
Alias: `simpleJSONExtractRaw`.
|
||||
|
||||
Examples:
|
||||
|
||||
``` sql
|
||||
visitParamExtractRaw('{"abc":"\\n\\u0000"}', 'abc') = '"\\n\\u0000"';
|
||||
visitParamExtractRaw('{"abc":{"def":[1,2,3]}}', 'abc') = '{"def":[1,2,3]}';
|
||||
```sql
|
||||
simpleJSONHas(json, field_name)
|
||||
```
|
||||
|
||||
## visitParamExtractString(params, name)
|
||||
**Parameters**
|
||||
|
||||
Parses the string in double quotes. The value is unescaped. If unescaping failed, it returns an empty string.
|
||||
- `json`: The JSON in which the field is searched for. [String](../../sql-reference/data-types/string.md#string)
|
||||
- `field_name`: The name of the field to search for. [String literal](../syntax#string)
|
||||
|
||||
Alias: `simpleJSONExtractString`.
|
||||
**Returned value**
|
||||
|
||||
Examples:
|
||||
It returns `1` if the field exists, `0` otherwise.
|
||||
|
||||
``` sql
|
||||
visitParamExtractString('{"abc":"\\n\\u0000"}', 'abc') = '\n\0';
|
||||
visitParamExtractString('{"abc":"\\u263a"}', 'abc') = '☺';
|
||||
visitParamExtractString('{"abc":"\\u263"}', 'abc') = '';
|
||||
visitParamExtractString('{"abc":"hello}', 'abc') = '';
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
CREATE TABLE jsons
|
||||
(
|
||||
`json` String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"true","qux":1}');
|
||||
|
||||
SELECT simpleJSONHas(json, 'foo') FROM jsons;
|
||||
SELECT simpleJSONHas(json, 'bar') FROM jsons;
|
||||
```
|
||||
|
||||
```response
|
||||
1
|
||||
0
|
||||
```
|
||||
## simpleJSONExtractUInt
|
||||
|
||||
Parses `UInt64` from the value of the field named `field_name`. If this is a string field, it tries to parse a number from the beginning of the string. If the field does not exist, or it exists but does not contain a number, it returns `0`.
|
||||
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
simpleJSONExtractUInt(json, field_name)
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `json`: The JSON in which the field is searched for. [String](../../sql-reference/data-types/string.md#string)
|
||||
- `field_name`: The name of the field to search for. [String literal](../syntax#string)
|
||||
|
||||
**Returned value**
|
||||
|
||||
It returns the number parsed from the field if the field exists and contains a number, `0` otherwise.
|
||||
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
CREATE TABLE jsons
|
||||
(
|
||||
`json` String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"4e3"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":3.4}');
|
||||
INSERT INTO jsons VALUES ('{"foo":5}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"not1number"}');
|
||||
INSERT INTO jsons VALUES ('{"baz":2}');
|
||||
|
||||
SELECT simpleJSONExtractUInt(json, 'foo') FROM jsons ORDER BY json;
|
||||
```
|
||||
|
||||
```response
|
||||
0
|
||||
4
|
||||
0
|
||||
3
|
||||
5
|
||||
```
|
||||
|
||||
## simpleJSONExtractInt
|
||||
|
||||
Parses `Int64` from the value of the field named `field_name`. If this is a string field, it tries to parse a number from the beginning of the string. If the field does not exist, or it exists but does not contain a number, it returns `0`.
|
||||
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
simpleJSONExtractInt(json, field_name)
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `json`: The JSON in which the field is searched for. [String](../../sql-reference/data-types/string.md#string)
|
||||
- `field_name`: The name of the field to search for. [String literal](../syntax#string)
|
||||
|
||||
**Returned value**
|
||||
|
||||
It returns the number parsed from the field if the field exists and contains a number, `0` otherwise.
|
||||
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
CREATE TABLE jsons
|
||||
(
|
||||
`json` String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"-4e3"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":-3.4}');
|
||||
INSERT INTO jsons VALUES ('{"foo":5}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"not1number"}');
|
||||
INSERT INTO jsons VALUES ('{"baz":2}');
|
||||
|
||||
SELECT simpleJSONExtractInt(json, 'foo') FROM jsons ORDER BY json;
|
||||
```
|
||||
|
||||
```response
|
||||
0
|
||||
-4
|
||||
0
|
||||
-3
|
||||
5
|
||||
```
|
||||
|
||||
## simpleJSONExtractFloat
|
||||
|
||||
Parses `Float64` from the value of the field named `field_name`. If this is a string field, it tries to parse a number from the beginning of the string. If the field does not exist, or it exists but does not contain a number, it returns `0`.
|
||||
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
simpleJSONExtractFloat(json, field_name)
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `json`: The JSON in which the field is searched for. [String](../../sql-reference/data-types/string.md#string)
|
||||
- `field_name`: The name of the field to search for. [String literal](../syntax#string)
|
||||
|
||||
**Returned value**
|
||||
|
||||
It returns the number parsed from the field if the field exists and contains a number, `0` otherwise.
|
||||
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
CREATE TABLE jsons
|
||||
(
|
||||
`json` String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"-4e3"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":-3.4}');
|
||||
INSERT INTO jsons VALUES ('{"foo":5}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"not1number"}');
|
||||
INSERT INTO jsons VALUES ('{"baz":2}');
|
||||
|
||||
SELECT simpleJSONExtractFloat(json, 'foo') FROM jsons ORDER BY json;
|
||||
```
|
||||
|
||||
```response
|
||||
0
|
||||
-4000
|
||||
0
|
||||
-3.4
|
||||
5
|
||||
```
|
||||
|
||||
## simpleJSONExtractBool
|
||||
|
||||
Parses a true/false value from the value of the field named `field_name`. The result is `UInt8`.
|
||||
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
simpleJSONExtractBool(json, field_name)
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `json`: The JSON in which the field is searched for. [String](../../sql-reference/data-types/string.md#string)
|
||||
- `field_name`: The name of the field to search for. [String literal](../syntax#string)
|
||||
|
||||
**Returned value**
|
||||
|
||||
It returns `1` if the value of the field is `true`, `0` otherwise. This means this function will return `0` including (and not only) in the following cases:
|
||||
- If the field doesn't exists.
|
||||
- If the field contains `true` as a string, e.g.: `{"field":"true"}`.
|
||||
- If the field contains `1` as a numerical value.
|
||||
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
CREATE TABLE jsons
|
||||
(
|
||||
`json` String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":false,"bar":true}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"true","qux":1}');
|
||||
|
||||
SELECT simpleJSONExtractBool(json, 'bar') FROM jsons ORDER BY json;
|
||||
SELECT simpleJSONExtractBool(json, 'foo') FROM jsons ORDER BY json;
|
||||
```
|
||||
|
||||
```response
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
```
|
||||
|
||||
## simpleJSONExtractRaw
|
||||
|
||||
Returns the value of the field named `field_name` as a `String`, including separators.
|
||||
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
simpleJSONExtractRaw(json, field_name)
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `json`: The JSON in which the field is searched for. [String](../../sql-reference/data-types/string.md#string)
|
||||
- `field_name`: The name of the field to search for. [String literal](../syntax#string)
|
||||
|
||||
**Returned value**
|
||||
|
||||
It returns the value of the field as a [`String`](../../sql-reference/data-types/string.md#string), including separators if the field exists, or an empty `String` otherwise.
|
||||
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
CREATE TABLE jsons
|
||||
(
|
||||
`json` String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"-4e3"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":-3.4}');
|
||||
INSERT INTO jsons VALUES ('{"foo":5}');
|
||||
INSERT INTO jsons VALUES ('{"foo":{"def":[1,2,3]}}');
|
||||
INSERT INTO jsons VALUES ('{"baz":2}');
|
||||
|
||||
SELECT simpleJSONExtractRaw(json, 'foo') FROM jsons ORDER BY json;
|
||||
```
|
||||
|
||||
```response
|
||||
|
||||
"-4e3"
|
||||
-3.4
|
||||
5
|
||||
{"def":[1,2,3]}
|
||||
```
|
||||
|
||||
## simpleJSONExtractString
|
||||
|
||||
Parses `String` in double quotes from the value of the field named `field_name`.
|
||||
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
simpleJSONExtractString(json, field_name)
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `json`: The JSON in which the field is searched for. [String](../../sql-reference/data-types/string.md#string)
|
||||
- `field_name`: The name of the field to search for. [String literal](../syntax#string)
|
||||
|
||||
**Returned value**
|
||||
|
||||
It returns the value of a field as a [`String`](../../sql-reference/data-types/string.md#string), including separators. The value is unescaped. It returns an empty `String`: if the field doesn't contain a double quoted string, if unescaping fails or if the field doesn't exist.
|
||||
|
||||
**Implementation details**
|
||||
|
||||
There is currently no support for code points in the format `\uXXXX\uYYYY` that are not from the basic multilingual plane (they are converted to CESU-8 instead of UTF-8).
|
||||
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
CREATE TABLE jsons
|
||||
(
|
||||
`json` String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"\\n\\u0000"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"\\u263"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"\\u263a"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"hello}');
|
||||
|
||||
SELECT simpleJSONExtractString(json, 'foo') FROM jsons ORDER BY json;
|
||||
```
|
||||
|
||||
```response
|
||||
\n\0
|
||||
|
||||
☺
|
||||
|
||||
```
|
||||
|
||||
## visitParamHas
|
||||
|
||||
This function is [an alias of `simpleJSONHas`](./json-functions#simplejsonhas).
|
||||
|
||||
## visitParamExtractUInt
|
||||
|
||||
This function is [an alias of `simpleJSONExtractUInt`](./json-functions#simplejsonextractuint).
|
||||
|
||||
## visitParamExtractInt
|
||||
|
||||
This function is [an alias of `simpleJSONExtractInt`](./json-functions#simplejsonextractint).
|
||||
|
||||
## visitParamExtractFloat
|
||||
|
||||
This function is [an alias of `simpleJSONExtractFloat`](./json-functions#simplejsonextractfloat).
|
||||
|
||||
## visitParamExtractBool
|
||||
|
||||
This function is [an alias of `simpleJSONExtractBool`](./json-functions#simplejsonextractbool).
|
||||
|
||||
## visitParamExtractRaw
|
||||
|
||||
This function is [an alias of `simpleJSONExtractRaw`](./json-functions#simplejsonextractraw).
|
||||
|
||||
## visitParamExtractString
|
||||
|
||||
This function is [an alias of `simpleJSONExtractString`](./json-functions#simplejsonextractstring).
|
||||
|
||||
# JSONExtract functions
|
||||
|
||||
The following functions are based on [simdjson](https://github.com/lemire/simdjson) designed for more complex JSON parsing requirements.
|
||||
|
@ -299,6 +299,18 @@ sin(x)
|
||||
|
||||
Type: [Float*](../../sql-reference/data-types/float.md).
|
||||
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
SELECT sin(1.23);
|
||||
```
|
||||
|
||||
```response
|
||||
0.9424888019316975
|
||||
```
|
||||
|
||||
## cos
|
||||
|
||||
Returns the cosine of the argument.
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <Common/FunctionDocumentation.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
@ -31,14 +33,7 @@ std::string FunctionDocumentation::examplesAsString() const
|
||||
|
||||
std::string FunctionDocumentation::categoriesAsString() const
|
||||
{
|
||||
if (categories.empty())
|
||||
return "";
|
||||
|
||||
auto it = categories.begin();
|
||||
std::string res = *it;
|
||||
for (; it != categories.end(); ++it)
|
||||
res += ", " + *it;
|
||||
return res;
|
||||
return boost::algorithm::join(categories, ", ");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,15 @@ using FunctionSin = FunctionMathUnary<UnaryFunctionVectorized<SinName, sin>>;
|
||||
|
||||
REGISTER_FUNCTION(Sin)
|
||||
{
|
||||
factory.registerFunction<FunctionSin>({}, FunctionFactory::CaseInsensitive);
|
||||
factory.registerFunction<FunctionSin>(
|
||||
FunctionDocumentation{
|
||||
.description = "Returns the sine of the argument.",
|
||||
.syntax = "sin(x)",
|
||||
.arguments = {{"x", "The number whose sine will be returned. (U)Int*, Float* or Decimal*."}},
|
||||
.returned_value = "The sine of x.",
|
||||
.examples = {{.name = "simple", .query = "SELECT sin(1.23)", .result = "0.9424888019316975"}},
|
||||
.categories{"Mathematical", "Trigonometric"}},
|
||||
FunctionFactory::CaseInsensitive);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,35 @@ using FunctionSimpleJSONExtractBool = FunctionsStringSearch<ExtractParamImpl<Nam
|
||||
|
||||
REGISTER_FUNCTION(VisitParamExtractBool)
|
||||
{
|
||||
factory.registerFunction<FunctionSimpleJSONExtractBool>();
|
||||
factory.registerFunction<FunctionSimpleJSONExtractBool>(FunctionDocumentation{
|
||||
.description = "Parses a true/false value from the value of the field named field_name. The result is UInt8.",
|
||||
.syntax = "simpleJSONExtractBool(json, field_name)",
|
||||
.arguments
|
||||
= {{"json", "The JSON in which the field is searched for. String."},
|
||||
{"field_name", "The name of the field to search for. String literal."}},
|
||||
.returned_value
|
||||
= R"(It returns 1 if the value of the field is true, 0 otherwise. This means this function will return 0 including (and not only) in the following cases:
|
||||
- If the field doesn't exists.
|
||||
- If the field contains true as a string, e.g.: {"field":"true"}.
|
||||
- If the field contains 1 as a numerical value.)",
|
||||
.examples
|
||||
= {{.name = "simple",
|
||||
.query = R"(CREATE TABLE jsons
|
||||
(
|
||||
json String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":false,"bar":true}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"true","qux":1}');
|
||||
|
||||
SELECT simpleJSONExtractBool(json, 'bar') FROM jsons ORDER BY json;
|
||||
SELECT simpleJSONExtractBool(json, 'foo') FROM jsons ORDER BY json;)",
|
||||
.result = R"(0
|
||||
1
|
||||
0
|
||||
0)"}},
|
||||
.categories{"JSON"}});
|
||||
factory.registerAlias("visitParamExtractBool", "simpleJSONExtractBool");
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,36 @@ using FunctionSimpleJSONExtractFloat = FunctionsStringSearch<ExtractParamImpl<Na
|
||||
|
||||
REGISTER_FUNCTION(VisitParamExtractFloat)
|
||||
{
|
||||
factory.registerFunction<FunctionSimpleJSONExtractFloat>();
|
||||
factory.registerFunction<FunctionSimpleJSONExtractFloat>(FunctionDocumentation{
|
||||
.description
|
||||
= "Parses Float64 from the value of the field named field_name. If this is a string field, it tries to parse a number from the "
|
||||
"beginning of the string. If the field does not exist, or it exists but does not contain a number, it returns 0.",
|
||||
.syntax = "simpleJSONExtractFloat(json, field_name)",
|
||||
.arguments
|
||||
= {{"json", "The JSON in which the field is searched for. String."},
|
||||
{"field_name", "The name of the field to search for. String literal."}},
|
||||
.returned_value = "It returns the number parsed from the field if the field exists and contains a number, 0 otherwise.",
|
||||
.examples
|
||||
= {{.name = "simple",
|
||||
.query = R"(CREATE TABLE jsons
|
||||
(
|
||||
json String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"-4e3"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":-3.4}');
|
||||
INSERT INTO jsons VALUES ('{"foo":5}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"not1number"}');
|
||||
INSERT INTO jsons VALUES ('{"baz":2}');
|
||||
|
||||
SELECT simpleJSONExtractFloat(json, 'foo') FROM jsons ORDER BY json;)",
|
||||
.result = R"(0
|
||||
-4000
|
||||
0
|
||||
-3.4
|
||||
5)"}},
|
||||
.categories{"JSON"}});
|
||||
factory.registerAlias("visitParamExtractFloat", "simpleJSONExtractFloat");
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,36 @@ using FunctionSimpleJSONExtractInt = FunctionsStringSearch<ExtractParamImpl<Name
|
||||
|
||||
REGISTER_FUNCTION(VisitParamExtractInt)
|
||||
{
|
||||
factory.registerFunction<FunctionSimpleJSONExtractInt>();
|
||||
factory.registerFunction<FunctionSimpleJSONExtractInt>(FunctionDocumentation{
|
||||
.description
|
||||
= "Parses Int64 from the value of the field named field_name. If this is a string field, it tries to parse a number from the "
|
||||
"beginning of the string. If the field does not exist, or it exists but does not contain a number, it returns 0.",
|
||||
.syntax = "simpleJSONExtractInt(json, field_name)",
|
||||
.arguments
|
||||
= {{"json", "The JSON in which the field is searched for. String."},
|
||||
{"field_name", "The name of the field to search for. String literal."}},
|
||||
.returned_value = "It returns the number parsed from the field if the field exists and contains a number, 0 otherwise.",
|
||||
.examples
|
||||
= {{.name = "simple",
|
||||
.query = R"(CREATE TABLE jsons
|
||||
(
|
||||
json String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"-4e3"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":-3.4}');
|
||||
INSERT INTO jsons VALUES ('{"foo":5}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"not1number"}');
|
||||
INSERT INTO jsons VALUES ('{"baz":2}');
|
||||
|
||||
SELECT simpleJSONExtractInt(json, 'foo') FROM jsons ORDER BY json;)",
|
||||
.result = R"(0
|
||||
-4
|
||||
0
|
||||
-3
|
||||
5)"}},
|
||||
.categories{"JSON"}});
|
||||
factory.registerAlias("visitParamExtractInt", "simpleJSONExtractInt");
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,35 @@ using FunctionSimpleJSONExtractRaw = FunctionsStringSearchToString<ExtractParamT
|
||||
|
||||
REGISTER_FUNCTION(VisitParamExtractRaw)
|
||||
{
|
||||
factory.registerFunction<FunctionSimpleJSONExtractRaw>();
|
||||
factory.registerFunction<FunctionSimpleJSONExtractRaw>(FunctionDocumentation{
|
||||
.description = "Returns the value of the field named field_name as a String, including separators.",
|
||||
.syntax = "simpleJSONExtractRaw(json, field_name)",
|
||||
.arguments
|
||||
= {{"json", "The JSON in which the field is searched for. String."},
|
||||
{"field_name", "The name of the field to search for. String literal."}},
|
||||
.returned_value
|
||||
= "It returns the value of the field as a String including separators if the field exists, or an empty String otherwise.",
|
||||
.examples
|
||||
= {{.name = "simple",
|
||||
.query = R"(CREATE TABLE jsons
|
||||
(
|
||||
json String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"-4e3"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":-3.4}');
|
||||
INSERT INTO jsons VALUES ('{"foo":5}');
|
||||
INSERT INTO jsons VALUES ('{"foo":{"def":[1,2,3]}}');
|
||||
INSERT INTO jsons VALUES ('{"baz":2}');
|
||||
|
||||
SELECT simpleJSONExtractRaw(json, 'foo') FROM jsons ORDER BY json;)",
|
||||
.result = R"(
|
||||
"-4e3"
|
||||
-3.4
|
||||
5
|
||||
{"def":[1,2,3]})"}},
|
||||
.categories{"JSON"}});
|
||||
factory.registerAlias("visitParamExtractRaw", "simpleJSONExtractRaw");
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,35 @@ using FunctionSimpleJSONExtractString = FunctionsStringSearchToString<ExtractPar
|
||||
|
||||
REGISTER_FUNCTION(VisitParamExtractString)
|
||||
{
|
||||
factory.registerFunction<FunctionSimpleJSONExtractString>();
|
||||
factory.registerFunction<FunctionSimpleJSONExtractString>(FunctionDocumentation{
|
||||
.description = R"(Parses String in double quotes from the value of the field named field_name.
|
||||
|
||||
There is currently no support for code points in the format \uXXXX\uYYYY that are not from the basic multilingual plane (they are converted to CESU-8 instead of UTF-8).)",
|
||||
.syntax = "simpleJSONExtractString(json, field_name)",
|
||||
.arguments
|
||||
= {{"json", "The JSON in which the field is searched for. String."},
|
||||
{"field_name", "The name of the field to search for. String literal."}},
|
||||
.returned_value = "It returns the value of a field as a String, including separators. The value is unescaped. It returns an empty "
|
||||
"String: if the field doesn't contain a double quoted string, if unescaping fails or if the field doesn't exist.",
|
||||
.examples
|
||||
= {{.name = "simple",
|
||||
.query = R"(CREATE TABLE jsons
|
||||
(
|
||||
json String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"\\n\\u0000"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"\\u263"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"\\u263a"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"hello}');
|
||||
|
||||
SELECT simpleJSONExtractString(json, 'foo') FROM jsons ORDER BY json;)",
|
||||
.result = R"(\n\0
|
||||
|
||||
☺
|
||||
)"}},
|
||||
.categories{"JSON"}});
|
||||
factory.registerAlias("visitParamExtractString", "simpleJSONExtractString");
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,36 @@ using FunctionSimpleJSONExtractUInt = FunctionsStringSearch<ExtractParamImpl<Nam
|
||||
|
||||
REGISTER_FUNCTION(VisitParamExtractUInt)
|
||||
{
|
||||
factory.registerFunction<FunctionSimpleJSONExtractUInt>();
|
||||
factory.registerFunction<FunctionSimpleJSONExtractUInt>(FunctionDocumentation{
|
||||
.description
|
||||
= "Parses UInt64 from the value of the field named field_name. If this is a string field, it tries to parse a number from the "
|
||||
"beginning of the string. If the field does not exist, or it exists but does not contain a number, it returns 0.",
|
||||
.syntax = "simpleJSONExtractUInt(json, field_name)",
|
||||
.arguments
|
||||
= {{"json", "The JSON in which the field is searched for. String."},
|
||||
{"field_name", "The name of the field to search for. String literal."}},
|
||||
.returned_value = "It returns the number parsed from the field if the field exists and contains a number, 0 otherwise.",
|
||||
.examples
|
||||
= {{.name = "simple",
|
||||
.query = R"(CREATE TABLE jsons
|
||||
(
|
||||
json String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"4e3"}');
|
||||
INSERT INTO jsons VALUES ('{"foo":3.4}');
|
||||
INSERT INTO jsons VALUES ('{"foo":5}');
|
||||
INSERT INTO jsons VALUES ('{"foo":"not1number"}');
|
||||
INSERT INTO jsons VALUES ('{"baz":2}');
|
||||
|
||||
SELECT simpleJSONExtractUInt(json, 'foo') FROM jsons ORDER BY json;)",
|
||||
.result = R"(0
|
||||
4
|
||||
0
|
||||
3
|
||||
5)"}},
|
||||
.categories{"JSON"}});
|
||||
factory.registerAlias("visitParamExtractUInt", "simpleJSONExtractUInt");
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,28 @@ using FunctionSimpleJSONHas = FunctionsStringSearch<ExtractParamImpl<NameSimpleJ
|
||||
|
||||
REGISTER_FUNCTION(VisitParamHas)
|
||||
{
|
||||
factory.registerFunction<FunctionSimpleJSONHas>();
|
||||
factory.registerFunction<FunctionSimpleJSONHas>(FunctionDocumentation{
|
||||
.description = "Checks whether there is a field named field_name. The result is UInt8.",
|
||||
.syntax = "simpleJSONHas(json, field_name)",
|
||||
.arguments
|
||||
= {{"json", "The JSON in which the field is searched for. String."},
|
||||
{"field_name", "The name of the field to search for. String literal."}},
|
||||
.returned_value = "It returns 1 if the field exists, 0 otherwise.",
|
||||
.examples
|
||||
= {{.name = "simple",
|
||||
.query = R"(CREATE TABLE jsons
|
||||
(
|
||||
json String
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO jsons VALUES ('{"foo":"true","qux":1}');
|
||||
|
||||
SELECT simpleJSONHas(json, 'foo') FROM jsons;
|
||||
SELECT simpleJSONHas(json, 'bar') FROM jsons;)",
|
||||
.result = R"(1
|
||||
0)"}},
|
||||
.categories{"JSON"}});
|
||||
factory.registerAlias("visitParamHas", "simpleJSONHas");
|
||||
}
|
||||
|
||||
|
@ -644,14 +644,6 @@ shardNum
|
||||
showCertificate
|
||||
sigmoid
|
||||
sign
|
||||
simpleJSONExtractBool
|
||||
simpleJSONExtractFloat
|
||||
simpleJSONExtractInt
|
||||
simpleJSONExtractRaw
|
||||
simpleJSONExtractString
|
||||
simpleJSONExtractUInt
|
||||
simpleJSONHas
|
||||
sin
|
||||
sinh
|
||||
sipHash128
|
||||
sipHash128Keyed
|
||||
|
@ -1,4 +1,4 @@
|
||||
personal_ws-1.1 en 2724
|
||||
personal_ws-1.1 en 2758
|
||||
AArch
|
||||
ACLs
|
||||
ALTERs
|
||||
@ -845,7 +845,6 @@ SendScalars
|
||||
ShareAlike
|
||||
SharedMergeTree
|
||||
Shortkeys
|
||||
Shortkeys
|
||||
SimHash
|
||||
Simhash
|
||||
SimpleAggregateFunction
|
||||
@ -1705,7 +1704,6 @@ hyperscan
|
||||
hypot
|
||||
hyvor
|
||||
iTerm
|
||||
iTerm
|
||||
icosahedron
|
||||
icudata
|
||||
idempotency
|
||||
@ -2332,6 +2330,14 @@ shortcircuit
|
||||
shortkeys
|
||||
shoutout
|
||||
simdjson
|
||||
simpleJSON
|
||||
simpleJSONExtractBool
|
||||
simpleJSONExtractFloat
|
||||
simpleJSONExtractInt
|
||||
simpleJSONExtractRaw
|
||||
simpleJSONExtractString
|
||||
simpleJSONExtractUInt
|
||||
simpleJSONHas
|
||||
simpleLinearRegression
|
||||
simpleaggregatefunction
|
||||
simplelinearregression
|
||||
|
Loading…
Reference in New Issue
Block a user