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
18 changes: 18 additions & 0 deletions interactive_engine/executor/ir/core/src/plan/logical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4944,4 +4944,22 @@ mod test {
.unwrap()
);
}

#[test]
fn test_data_type_conversion() {
let schema =
Schema::from_json(std::fs::File::open("resource/modern_schema_pk.json").unwrap()).unwrap();
for entity in schema.get_entities() {
let columns = &entity.columns;
for column in columns {
assert!(column.data_type.is_some());
}
}
for relation in schema.get_relations() {
let columns = &relation.columns;
for column in columns {
assert!(&column.data_type.is_some());
}
}
}
}
43 changes: 27 additions & 16 deletions interactive_engine/executor/ir/core/src/plan/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ impl Schema {
(false, 0)
}
}

pub(crate) fn get_entities(&self) -> &Vec<schema_pb::EntityMeta> {
self.entities.as_ref()
}

pub(crate) fn get_relations(&self) -> &Vec<schema_pb::RelationMeta> {
self.relations.as_ref()
}
}

impl From<Schema> for schema_pb::Schema {
Expand Down Expand Up @@ -492,33 +500,36 @@ impl JsonIO for Schema {
// }
fn convert_data_type(data_type_int: i64) -> serde_json::Value {
use serde_json::json;
match data_type_int {
let dt = match data_type_int {
// Primitive types mapping
0 => json!({ "primitive_type": "DT_BOOL" }), // BOOLEAN
1 => json!({ "primitive_type": "DT_SIGNED_INT32" }), // INT32
2 => json!({ "primitive_type": "DT_SIGNED_INT64" }), // INT64
3 => json!({ "primitive_type": "DT_DOUBLE" }), // DOUBLE
0 => json!({ "PrimitiveType": 5 }), // BOOLEAN
1 => json!({ "PrimitiveType": 1 }), // INT32
2 => json!({ "PrimitiveType": 3 }), // INT64
3 => json!({ "PrimitiveType": 7 }), // DOUBLE

// String type mapping
4 => json!({ "string": { "long_text": {} } }), // STRING
4 => json!({ "String": { "item": {"LongText": {}} } }), // STRING

// Array types mapping
6 => json!({ "array": { "component_type": { "primitive_type": "DT_SIGNED_INT32" } } }), // INT32_ARRAY
7 => json!({ "array": { "component_type": { "primitive_type": "DT_SIGNED_INT64" } } }), // INT64_ARRAY
8 => json!({ "array": { "component_type": { "primitive_type": "DT_DOUBLE" } } }), // DOUBLE_ARRAY
9 => json!({ "array": { "component_type": { "string": { "long_text": {} } } } }), // STRING_ARRAY
6 => json!({ "Array": { "component_type": { "item": {"PrimitiveType": 1 } }} , "max_length": 1024}), // INT32_ARRAY
7 => json!({ "Array": { "component_type": { "item": {"PrimitiveType": 3 }} } , "max_length": 1024}), // INT64_ARRAY
8 => json!({ "Array": { "component_type": { "item": {"PrimitiveType": 7 }} } , "max_length": 1024}), // DOUBLE_ARRAY
9 => {
json!({ "Array": { "component_type": { "item": { "String": { "item": {"LongText": {}} } } } , "max_length": 1024} })
} // STRING_ARRAY

// None type mapping
11 => json!({ "primitive_type": "DT_NULL" }), // NONE
11 => json!({ "PrimitiveType": 8 }), // NONE

// Temporal types mapping
12 => json!({ "temporal": { "date32": {} } }), // DATE32
13 => json!({ "temporal": { "time32": {} } }), // TIME32
14 => json!({ "temporal": { "timestamp": {} } }), // TIMESTAMP
12 => json!({ "Temporal": { "item": {"Date32": {} }} }), // DATE32
13 => json!({ "Temporal": {"item": { "Time32": {} }} }), // TIME32
14 => json!({ "Temporal": { "item": {"Timestamp": {} }} }), // TIMESTAMP

// Other types handling (default to a NONE-like type if applicable)
_ => json!({ "primitive_type": "DT_ANY" }), // NONE or unsupported types
}
_ => json!({ "PrimitiveType": 0 }), // NONE or unsupported types
};
json!({"item": dt})
}

/// To define the options of required columns by the computing node of the query plan.
Expand Down
Loading