Skip to content

Commit 932d0eb

Browse files
Scalar type representation (#165)
<!-- The PR description should answer 2 (maybe 3) important questions: --> ### What Return proper representation for scalar types. Still need to verify and/or fix serialization of types. <!-- What is this PR trying to accomplish (and why, if it's not obvious)? --> ### How <!-- How is it trying to accomplish it (what are the implementation steps)? --> --------- Co-authored-by: Daniel Harvey <[email protected]>
1 parent 915b1a6 commit 932d0eb

File tree

10 files changed

+213
-31
lines changed

10 files changed

+213
-31
lines changed

crates/configuration/src/introspection.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Configuration and state for our connector.
2+
use ndc_models::TypeRepresentation;
23
use serde::Deserialize;
34

45
#[derive(Deserialize, Debug)]
@@ -64,3 +65,32 @@ pub struct IntrospectionForeignKeyColumn {
6465
pub struct IntrospectionSchema {
6566
pub name: String,
6667
}
68+
69+
pub fn map_type_representation(sql_type: &str) -> Option<TypeRepresentation> {
70+
match sql_type.to_lowercase().as_str() {
71+
"bigint" => Some(TypeRepresentation::Int64),
72+
"bit" => Some(TypeRepresentation::Boolean),
73+
"decimal" | "numeric" | "money" | "smallmoney" => Some(TypeRepresentation::BigDecimal),
74+
"int" => Some(TypeRepresentation::Int32),
75+
"smallint" => Some(TypeRepresentation::Int16),
76+
"tinyint" => Some(TypeRepresentation::Int16),
77+
"float" => Some(TypeRepresentation::Float64),
78+
"real" => Some(TypeRepresentation::Float32),
79+
"date" => Some(TypeRepresentation::Date),
80+
"datetime" | "datetime2" | "smalldatetime" => Some(TypeRepresentation::Timestamp),
81+
"datetimeoffset" => Some(TypeRepresentation::TimestampTZ),
82+
"time" | "timestamp" => Some(TypeRepresentation::String),
83+
"char" | "varchar" | "text" | "nchar" | "nvarchar" | "ntext" => {
84+
Some(TypeRepresentation::String)
85+
}
86+
"binary" | "varbinary" | "image" => Some(TypeRepresentation::String),
87+
"uniqueidentifier" => Some(TypeRepresentation::UUID),
88+
"xml" => Some(TypeRepresentation::String),
89+
"json" => Some(TypeRepresentation::JSON),
90+
// TODO: Add support for hierarchyid and sql_variant
91+
// "geometry" => Some(TypeRepresentation::Geometry),
92+
// "geography" => Some(TypeRepresentation::Geography),
93+
// "hierarchyid" | "sql_variant" => XXX,
94+
_ => None,
95+
}
96+
}

crates/ndc-sqlserver/src/schema.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ use ndc_sdk::models::ObjectTypeName;
1212
use ndc_sdk::models::ProcedureName;
1313
use ndc_sdk::models::ScalarTypeName;
1414
use ndc_sdk::models::TypeRepresentation;
15-
use query_engine_metadata::metadata;
16-
1715
use ndc_sqlserver_configuration as configuration;
16+
use query_engine_metadata::metadata;
1817
use query_engine_metadata::metadata::stored_procedures::{
1918
StoredProcedureArgumentInfo, StoredProcedures,
2019
};
@@ -308,8 +307,9 @@ pub fn get_schema(
308307
(
309308
scalar_type.0.clone().into(),
310309
models::ScalarType {
311-
// TODO(PY): Add representation for beta
312-
representation: None,
310+
representation: configuration::introspection::map_type_representation(
311+
scalar_type.0.as_str(),
312+
),
313313
aggregate_functions: metadata
314314
.aggregate_functions
315315
.0

crates/ndc-sqlserver/tests/snapshots/mutation_tests__stored_procedures__execute_stored_procedure_with_relationships.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ expression: result
1313
"rows": [
1414
{
1515
"InvoiceId": 98,
16-
"Total": 3.98
16+
"Total": "3.98"
1717
},
1818
{
1919
"InvoiceId": 121,
20-
"Total": 3.96
20+
"Total": "3.96"
2121
},
2222
{
2323
"InvoiceId": 143,
24-
"Total": 5.94
24+
"Total": "5.94"
2525
},
2626
{
2727
"InvoiceId": 195,
28-
"Total": 0.99
28+
"Total": "0.99"
2929
},
3030
{
3131
"InvoiceId": 316,
32-
"Total": 1.98
32+
"Total": "1.98"
3333
},
3434
{
3535
"InvoiceId": 327,
36-
"Total": 13.86
36+
"Total": "13.86"
3737
},
3838
{
3939
"InvoiceId": 382,
40-
"Total": 8.91
40+
"Total": "8.91"
4141
}
4242
]
4343
}

crates/ndc-sqlserver/tests/snapshots/query_tests__types__select_value_types.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ expression: result
66
{
77
"rows": [
88
{
9-
"bigint": 1,
9+
"bigint": "1",
1010
"int": 245,
1111
"float": 24.555,
12-
"numeric": 24.555,
12+
"numeric": "24.555",
1313
"char": "s",
1414
"text": "textual text",
1515
"date": "2021-12-21",

0 commit comments

Comments
 (0)