Skip to content

Commit f577fae

Browse files
authored
fix(interactive): Fix bug in datatype conversion in ir-core (#4421)
<!-- Thanks for your contribution! please review https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before opening an issue. --> ## What do these changes do? <!-- Please give a short brief about these changes. --> As titled. ## Related issue number <!-- Are there any issues opened that will be resolved by merging this change? --> Fixes #4420
1 parent b052dd4 commit f577fae

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

interactive_engine/executor/ir/core/src/plan/logical.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,4 +4944,22 @@ mod test {
49444944
.unwrap()
49454945
);
49464946
}
4947+
4948+
#[test]
4949+
fn test_data_type_conversion() {
4950+
let schema =
4951+
Schema::from_json(std::fs::File::open("resource/modern_schema_pk.json").unwrap()).unwrap();
4952+
for entity in schema.get_entities() {
4953+
let columns = &entity.columns;
4954+
for column in columns {
4955+
assert!(column.data_type.is_some());
4956+
}
4957+
}
4958+
for relation in schema.get_relations() {
4959+
let columns = &relation.columns;
4960+
for column in columns {
4961+
assert!(&column.data_type.is_some());
4962+
}
4963+
}
4964+
}
49474965
}

interactive_engine/executor/ir/core/src/plan/meta.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ impl Schema {
231231
(false, 0)
232232
}
233233
}
234+
235+
pub(crate) fn get_entities(&self) -> &Vec<schema_pb::EntityMeta> {
236+
self.entities.as_ref()
237+
}
238+
239+
pub(crate) fn get_relations(&self) -> &Vec<schema_pb::RelationMeta> {
240+
self.relations.as_ref()
241+
}
234242
}
235243

236244
impl From<Schema> for schema_pb::Schema {
@@ -492,33 +500,36 @@ impl JsonIO for Schema {
492500
// }
493501
fn convert_data_type(data_type_int: i64) -> serde_json::Value {
494502
use serde_json::json;
495-
match data_type_int {
503+
let dt = match data_type_int {
496504
// Primitive types mapping
497-
0 => json!({ "primitive_type": "DT_BOOL" }), // BOOLEAN
498-
1 => json!({ "primitive_type": "DT_SIGNED_INT32" }), // INT32
499-
2 => json!({ "primitive_type": "DT_SIGNED_INT64" }), // INT64
500-
3 => json!({ "primitive_type": "DT_DOUBLE" }), // DOUBLE
505+
0 => json!({ "PrimitiveType": 5 }), // BOOLEAN
506+
1 => json!({ "PrimitiveType": 1 }), // INT32
507+
2 => json!({ "PrimitiveType": 3 }), // INT64
508+
3 => json!({ "PrimitiveType": 7 }), // DOUBLE
501509

502510
// String type mapping
503-
4 => json!({ "string": { "long_text": {} } }), // STRING
511+
4 => json!({ "String": { "item": {"LongText": {}} } }), // STRING
504512

505513
// Array types mapping
506-
6 => json!({ "array": { "component_type": { "primitive_type": "DT_SIGNED_INT32" } } }), // INT32_ARRAY
507-
7 => json!({ "array": { "component_type": { "primitive_type": "DT_SIGNED_INT64" } } }), // INT64_ARRAY
508-
8 => json!({ "array": { "component_type": { "primitive_type": "DT_DOUBLE" } } }), // DOUBLE_ARRAY
509-
9 => json!({ "array": { "component_type": { "string": { "long_text": {} } } } }), // STRING_ARRAY
514+
6 => json!({ "Array": { "component_type": { "item": {"PrimitiveType": 1 } }} , "max_length": 1024}), // INT32_ARRAY
515+
7 => json!({ "Array": { "component_type": { "item": {"PrimitiveType": 3 }} } , "max_length": 1024}), // INT64_ARRAY
516+
8 => json!({ "Array": { "component_type": { "item": {"PrimitiveType": 7 }} } , "max_length": 1024}), // DOUBLE_ARRAY
517+
9 => {
518+
json!({ "Array": { "component_type": { "item": { "String": { "item": {"LongText": {}} } } } , "max_length": 1024} })
519+
} // STRING_ARRAY
510520

511521
// None type mapping
512-
11 => json!({ "primitive_type": "DT_NULL" }), // NONE
522+
11 => json!({ "PrimitiveType": 8 }), // NONE
513523

514524
// Temporal types mapping
515-
12 => json!({ "temporal": { "date32": {} } }), // DATE32
516-
13 => json!({ "temporal": { "time32": {} } }), // TIME32
517-
14 => json!({ "temporal": { "timestamp": {} } }), // TIMESTAMP
525+
12 => json!({ "Temporal": { "item": {"Date32": {} }} }), // DATE32
526+
13 => json!({ "Temporal": {"item": { "Time32": {} }} }), // TIME32
527+
14 => json!({ "Temporal": { "item": {"Timestamp": {} }} }), // TIMESTAMP
518528

519529
// Other types handling (default to a NONE-like type if applicable)
520-
_ => json!({ "primitive_type": "DT_ANY" }), // NONE or unsupported types
521-
}
530+
_ => json!({ "PrimitiveType": 0 }), // NONE or unsupported types
531+
};
532+
json!({"item": dt})
522533
}
523534

524535
/// To define the options of required columns by the computing node of the query plan.

0 commit comments

Comments
 (0)