Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add json data type #4619

Merged
merged 30 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7836e03
feat: add json type and vector
CookiePieWw Aug 22, 2024
ed2f07d
fix: allow to create and insert json data
CookiePieWw Aug 23, 2024
f910b37
feat: udf to query json as string
CookiePieWw Aug 26, 2024
c334919
refactor: remove JsonbValue and JsonVector
CookiePieWw Aug 26, 2024
b2585ac
feat: show json value as strings
CookiePieWw Aug 27, 2024
45c853b
chore: make ci happy
CookiePieWw Aug 27, 2024
5e9e417
test: adunit test and sqlness test
CookiePieWw Aug 28, 2024
092ee0c
refactor: use binary as grpc value of json
CookiePieWw Aug 28, 2024
6d5241d
Merge branch 'main' into json
CookiePieWw Aug 28, 2024
cb88312
fix: use non-preserve-order jsonb
CookiePieWw Aug 29, 2024
7ceddd0
test: revert changed test
CookiePieWw Aug 29, 2024
26e8d1a
refactor: change udf get_by_path to jq
CookiePieWw Aug 29, 2024
d3752b3
chore: make ci happy
CookiePieWw Aug 29, 2024
601f647
fix: distinguish binary and json in proto
CookiePieWw Aug 30, 2024
13c370c
chore: delete udf for future pr
CookiePieWw Aug 30, 2024
619f490
refactor: remove Value(Json)
CookiePieWw Aug 30, 2024
9f07158
chore: follow review comments
CookiePieWw Aug 30, 2024
1c279e4
test: some tests and checks
CookiePieWw Aug 30, 2024
ae85538
test: fix unit tests
CookiePieWw Aug 31, 2024
411cf8f
chore: follow review comments
CookiePieWw Sep 2, 2024
3ca3d42
chore: corresponding changes to proto
CookiePieWw Sep 4, 2024
1f2d751
fix: change grpc and pgsql server behavior alongside with sqlness/cru…
CookiePieWw Sep 4, 2024
5645c63
chore: follow review comments
CookiePieWw Sep 5, 2024
d908a46
feat: udf of conversions between json and strings, used for grpc server
CookiePieWw Sep 5, 2024
34c15b0
refactor: rename to_string to json_to_string
CookiePieWw Sep 5, 2024
94e57be
chore: resolve merge conflict
CookiePieWw Sep 5, 2024
315b1e6
test: add more sqlness test for json
CookiePieWw Sep 5, 2024
ac3f9e1
chore: thanks for review :)
CookiePieWw Sep 5, 2024
65b71ce
chore: merge main into json
CookiePieWw Sep 9, 2024
9141eaa
Apply suggestions from code review
WenyXu Sep 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ etcd-client = { version = "0.13" }
fst = "0.4.7"
futures = "0.3"
futures-util = "0.3"
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "c437b55725b7f5224fe9d46db21072b4a682ee4b" }
greptime-proto = { git = "https://github.com/CookiePieWw/greptime-proto.git", rev = "4346f484c14bb8a6711d10906ee6db54a896030a" }
humantime = "2.1"
humantime-serde = "1.1"
itertools = "0.10"
jsonb = "0.4"
lazy_static = "1.4"
meter-core = { git = "https://github.com/GreptimeTeam/greptime-meter.git", rev = "80eb97c24c88af4dd9a86f8bbaf50e741d4eb8cd" }
mockall = "0.11.4"
Expand Down
20 changes: 17 additions & 3 deletions src/api/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl From<ColumnDataTypeWrapper> for ConcreteDataType {
ConcreteDataType::decimal128_default_datatype()
}
}
ColumnDataType::Json => ConcreteDataType::json_datatype(),
}
}
}
Expand Down Expand Up @@ -258,6 +259,7 @@ impl TryFrom<ConcreteDataType> for ColumnDataTypeWrapper {
IntervalType::MonthDayNano(_) => ColumnDataType::IntervalMonthDayNano,
},
ConcreteDataType::Decimal128(_) => ColumnDataType::Decimal128,
ConcreteDataType::Json(_) => ColumnDataType::Json,
ConcreteDataType::Null(_)
| ConcreteDataType::List(_)
| ConcreteDataType::Dictionary(_)
Expand Down Expand Up @@ -395,6 +397,10 @@ pub fn values_with_capacity(datatype: ColumnDataType, capacity: usize) -> Values
decimal128_values: Vec::with_capacity(capacity),
..Default::default()
},
ColumnDataType::Json => Values {
json_values: Vec::with_capacity(capacity),
..Default::default()
},
}
}

Expand Down Expand Up @@ -443,7 +449,7 @@ pub fn push_vals(column: &mut Column, origin_count: usize, vector: VectorRef) {
.push(convert_i128_to_interval(val.to_i128())),
},
Value::Decimal128(val) => values.decimal128_values.push(convert_to_pb_decimal128(val)),
Value::List(_) | Value::Duration(_) => unreachable!(),
Value::List(_) | Value::Duration(_) | Value::Json(_) => unreachable!(),
WenyXu marked this conversation as resolved.
Show resolved Hide resolved
});
column.null_mask = null_mask.into_vec();
}
Expand Down Expand Up @@ -569,6 +575,7 @@ pub fn pb_value_to_value_ref<'a>(
))
}
}
ValueData::JsonValue(v) => ValueRef::Json(v),
}
}

Expand Down Expand Up @@ -649,7 +656,8 @@ pub fn pb_values_to_vector_ref(data_type: &ConcreteDataType, values: Values) ->
ConcreteDataType::Null(_)
| ConcreteDataType::List(_)
| ConcreteDataType::Dictionary(_)
| ConcreteDataType::Duration(_) => {
| ConcreteDataType::Duration(_)
| ConcreteDataType::Json(_) => {
WenyXu marked this conversation as resolved.
Show resolved Hide resolved
unreachable!()
}
}
Expand Down Expand Up @@ -813,7 +821,8 @@ pub fn pb_values_to_values(data_type: &ConcreteDataType, values: Values) -> Vec<
ConcreteDataType::Null(_)
| ConcreteDataType::List(_)
| ConcreteDataType::Dictionary(_)
| ConcreteDataType::Duration(_) => {
| ConcreteDataType::Duration(_)
| ConcreteDataType::Json(_) => {
WenyXu marked this conversation as resolved.
Show resolved Hide resolved
unreachable!()
}
}
Expand Down Expand Up @@ -928,6 +937,9 @@ pub fn to_proto_value(value: Value) -> Option<v1::Value> {
Value::Decimal128(v) => v1::Value {
value_data: Some(ValueData::Decimal128Value(convert_to_pb_decimal128(v))),
},
Value::Json(v) => v1::Value {
value_data: Some(ValueData::JsonValue(v.to_vec())),
},
Value::List(_) | Value::Duration(_) => return None,
};

Expand Down Expand Up @@ -966,6 +978,7 @@ pub fn proto_value_type(value: &v1::Value) -> Option<ColumnDataType> {
ValueData::IntervalDayTimeValue(_) => ColumnDataType::IntervalDayTime,
ValueData::IntervalMonthDayNanoValue(_) => ColumnDataType::IntervalMonthDayNano,
ValueData::Decimal128Value(_) => ColumnDataType::Decimal128,
ValueData::JsonValue(_) => ColumnDataType::Json,
};
Some(value_type)
}
Expand Down Expand Up @@ -1023,6 +1036,7 @@ pub fn value_to_grpc_value(value: Value) -> GrpcValue {
}
}),
Value::Decimal128(v) => Some(ValueData::Decimal128Value(convert_to_pb_decimal128(v))),
Value::Json(v) => Some(ValueData::JsonValue(v.to_vec())),
Value::List(_) | Value::Duration(_) => unreachable!(),
},
}
Expand Down
1 change: 1 addition & 0 deletions src/common/function/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ common-time.workspace = true
common-version.workspace = true
datafusion.workspace = true
datatypes.workspace = true
jsonb.workspace = true
num = "0.4"
num-traits = "0.2"
once_cell.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions src/common/function/src/function_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::function::FunctionRef;
use crate::scalars::aggregate::{AggregateFunctionMetaRef, AggregateFunctions};
use crate::scalars::date::DateFunction;
use crate::scalars::expression::ExpressionFunction;
use crate::scalars::json::JsonFunction;
use crate::scalars::matches::MatchesFunction;
use crate::scalars::math::MathFunction;
use crate::scalars::numpy::NumpyFunction;
Expand Down Expand Up @@ -94,6 +95,9 @@ pub static FUNCTION_REGISTRY: Lazy<Arc<FunctionRegistry>> = Lazy::new(|| {
SystemFunction::register(&function_registry);
TableFunction::register(&function_registry);

// JSON functions
JsonFunction::register(&function_registry);

Arc::new(function_registry)
});

Expand Down
2 changes: 2 additions & 0 deletions src/common/function/src/scalars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
pub mod aggregate;
pub(crate) mod date;
pub mod expression;
pub mod json;
pub mod matches;
pub mod math;
pub mod numpy;

#[cfg(test)]
pub(crate) mod test;
pub(crate) mod timestamp;
Expand Down
28 changes: 28 additions & 0 deletions src/common/function/src/scalars/json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;
mod get_by_path;

use get_by_path::GetByPathFunction;

use crate::function_registry::FunctionRegistry;

pub(crate) struct JsonFunction;

impl JsonFunction {
pub fn register(registry: &FunctionRegistry) {
registry.register(Arc::new(GetByPathFunction));
}
}
Loading
Loading