Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions tests/it/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ async fn insert_with_json_hint() {
i UInt8,
jv JSON(
foo String,
bar Int
bar Int,
SKIPper String,
SKIP_REGEXP Int64
)
)
ENGINE = MergeTree
Expand All @@ -237,7 +239,9 @@ async fn insert_with_json_hint() {
i: 1,
jv: r#"{
"foo": "hello",
"bar": 123
"bar": 123,
"SKIPper": "kept",
"SKIP_REGEXP": 456
}"#
.to_string(),
};
Expand Down
37 changes: 36 additions & 1 deletion types/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ fn parse_json(input: &str) -> Result<DataTypeNode, TypesError> {
.into_iter()
.map(|column| column.trim())
.filter(|column| {
top_level_positions(column, b'=').next().is_none() && !column.starts_with("SKIP")
top_level_positions(column, b'=').next().is_none() && !column.starts_with("SKIP ")
})
.map(|column| {
let separator_index = top_level_positions(column, b' ').next().ok_or_else(|| {
Expand Down Expand Up @@ -1691,6 +1691,41 @@ mod tests {
}
}

#[test]
fn test_data_type_new_json_with_skip_prefixed_paths() {
for path in [
"SKIPper",
"SKIP_REGEXP",
"SKIP2",
"`SKIPped.nested`",
"`SKIP name`",
] {
let input = format!("JSON({path} String)");
let expected = DataTypeNode::JsonWithHint(vec![(
path.to_string(),
Box::new(DataTypeNode::String),
)]);
let parsed = DataTypeNode::new(&input).unwrap();
assert_eq!(parsed, expected, "Input: {input}");
assert_eq!(parsed.to_string(), input);
}
}

#[test]
fn test_data_type_new_json_with_skip_instructions_and_hints() {
assert_eq!(
DataTypeNode::new(
"JSON(max_dynamic_paths=10, SKIP ignored, SKIP REGEXP '^drop.*', SKIPper String, SKIP_REGEXP Int64, regular UInt8)"
)
.unwrap(),
DataTypeNode::JsonWithHint(vec![
("SKIPper".to_string(), Box::new(DataTypeNode::String)),
("SKIP_REGEXP".to_string(), Box::new(DataTypeNode::Int64)),
("regular".to_string(), Box::new(DataTypeNode::UInt8)),
])
);
}

#[test]
fn test_data_type_new_json_with_nested_hint_types() {
// a hint type with its own parentheses keeps its closing ones
Expand Down
Loading