Skip to content

Commit 00e8f5e

Browse files
committed
wip: fix ndc-tests
1 parent 72268a0 commit 00e8f5e

File tree

11 files changed

+295
-92
lines changed

11 files changed

+295
-92
lines changed

crates/configuration/src/config2.sql

+28-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,34 @@ WITH column_data AS (
66
c.column_name,
77
TO_JSON_STRING(STRUCT(
88
c.column_name AS name,
9-
JSON_OBJECT('ScalarType', c.data_type) AS type,
9+
JSON_OBJECT('ScalarType',
10+
case LOWER(c.data_type)
11+
when 'boolean' then 'boolean'
12+
when 'int16' then 'smallint'
13+
when 'smallint' then 'smallint'
14+
when 'int32' then 'integer'
15+
when 'integer' then 'integer'
16+
when 'int64' then 'bigint'
17+
when 'bigint' then 'bigint'
18+
when 'numeric' then 'numeric'
19+
when 'float64' then 'float'
20+
when 'float' then 'float'
21+
when 'real' then 'real'
22+
when 'double precision' then 'double precision'
23+
when 'text' then 'text'
24+
when 'string' then 'string'
25+
when 'character' then 'character'
26+
when 'json' then 'json'
27+
when 'jsonb' then 'jsonb'
28+
when 'date' then 'date'
29+
when 'time with time zone' then 'time with time zone'
30+
when 'time without time zone' then 'time without time zone'
31+
when 'timestamp with time zone' then 'timestamp with time zone'
32+
when 'timestamp without time zone' then 'timestamp without time zone'
33+
when 'uuid' then 'uuid'
34+
else 'any'
35+
end
36+
) AS type,
1037
CASE WHEN c.is_nullable = 'YES' THEN 'nullable' ELSE 'nonNullable' END AS nullable
1138
)) AS column_info
1239
FROM hasura_database_name.INFORMATION_SCHEMA.TABLES AS t

crates/configuration/src/version1.rs

+80-51
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub const DEFAULT_CONNECTION_URI_VARIABLE: &str = "HASURA_BIGQUERY_SERVICE_KEY";
3737
const CONFIGURATION_QUERY: &str = include_str!("config2.sql");
3838
const CONFIGURATION_JSONSCHEMA_FILENAME: &str = "schema.json";
3939

40-
const CHARACTER_STRINGS: [&str; 4] = ["char", "text", "varchar", "string"];
40+
const CHARACTER_STRINGS: [&str; 3] = ["character", "text", "string"];
4141
const UNICODE_CHARACTER_STRINGS: [&str; 3] = ["nchar", "ntext", "nvarchar"];
4242
const CANNOT_COMPARE: [&str; 3] = ["text", "ntext", "image"];
4343
const EXACT_NUMERICS: [&str; 9] = [
@@ -51,7 +51,7 @@ const EXACT_NUMERICS: [&str; 9] = [
5151
"smallmoney",
5252
"tinyint",
5353
];
54-
const APPROX_NUMERICS: [&str; 2] = ["float", "real"];
54+
const APPROX_NUMERICS: [&str; 3] = ["float", "real", "float64"];
5555
const NOT_COUNTABLE: [&str; 3] = ["image", "ntext", "text"];
5656
const NOT_APPROX_COUNTABLE: [&str; 4] = ["image", "sql_variant", "ntext", "text"];
5757

@@ -682,7 +682,7 @@ fn get_aggregate_functions_for_type(
682682
aggregate_functions.insert(
683683
AggregateFunctionName::new("COUNT".into()),
684684
database::AggregateFunction {
685-
return_type: TypeName::new("int".to_string().into()),
685+
return_type: TypeName::new("bigint".to_string().into()),
686686
},
687687
);
688688
}
@@ -691,66 +691,67 @@ fn get_aggregate_functions_for_type(
691691
&& (EXACT_NUMERICS.contains(&type_name.as_str())
692692
|| APPROX_NUMERICS.contains(&type_name.as_str())
693693
|| CHARACTER_STRINGS.contains(&type_name.as_str())
694+
|| type_name.as_str() == "date"
694695
|| type_name.as_str() == "datetime"
695-
|| type_name.as_str() == "uniqueidentifier")
696+
|| type_name.as_str() == "uuid")
696697
{
697698
aggregate_functions.insert(
698699
AggregateFunctionName::new("MIN".into()),
699700
database::AggregateFunction {
700-
return_type: TypeName::new(type_name.to_string().into()),
701+
return_type: TypeName::new(type_name.as_str().to_string().into()),
701702
},
702703
);
703704
aggregate_functions.insert(
704705
AggregateFunctionName::new("MAX".into()),
705706
database::AggregateFunction {
706-
return_type: TypeName::new(type_name.to_string().into()),
707+
return_type: TypeName::new(type_name.as_str().to_string().into()),
707708
},
708709
);
709710
}
710711

711-
if type_name.as_str() != "bit"
712-
&& (EXACT_NUMERICS.contains(&type_name.as_str())
713-
|| APPROX_NUMERICS.contains(&type_name.as_str()))
714-
{
715-
aggregate_functions.insert(
716-
AggregateFunctionName::new("STDEV".into()),
717-
database::AggregateFunction {
718-
return_type: TypeName::new("float".to_string().into()),
719-
},
720-
);
721-
aggregate_functions.insert(
722-
AggregateFunctionName::new("STDEVP".into()),
723-
database::AggregateFunction {
724-
return_type: TypeName::new("float".to_string().into()),
725-
},
726-
);
727-
aggregate_functions.insert(
728-
AggregateFunctionName::new("VAR".into()),
729-
database::AggregateFunction {
730-
return_type: TypeName::new("float".to_string().into()),
731-
},
732-
);
733-
aggregate_functions.insert(
734-
AggregateFunctionName::new("VARP".into()),
735-
database::AggregateFunction {
736-
return_type: TypeName::new("float".to_string().into()),
737-
},
738-
);
739-
}
712+
// if type_name.as_str() != "bit"
713+
// && (EXACT_NUMERICS.contains(&type_name.as_str())
714+
// || APPROX_NUMERICS.contains(&type_name.as_str()))
715+
// {
716+
// aggregate_functions.insert(
717+
// AggregateFunctionName::new("STDEV".into()),
718+
// database::AggregateFunction {
719+
// return_type: TypeName::new("float".to_string().into()),
720+
// },
721+
// );
722+
// aggregate_functions.insert(
723+
// AggregateFunctionName::new("STDEVP".into()),
724+
// database::AggregateFunction {
725+
// return_type: TypeName::new("float".to_string().into()),
726+
// },
727+
// );
728+
// aggregate_functions.insert(
729+
// AggregateFunctionName::new("VAR".into()),
730+
// database::AggregateFunction {
731+
// return_type: TypeName::new("float".to_string().into()),
732+
// },
733+
// );
734+
// aggregate_functions.insert(
735+
// AggregateFunctionName::new("VARP".into()),
736+
// database::AggregateFunction {
737+
// return_type: TypeName::new("float".to_string().into()),
738+
// },
739+
// );
740+
// }
740741

741742
if let Some(precise_return_type) = match type_name.as_str() {
742-
"tinyint" => Some("int"),
743-
"smallint" => Some("int"),
744-
"int" => Some("int"),
743+
"tinyint" => Some("smallint"),
744+
"smallint" => Some("smallint"),
745+
"int" => Some("integer"),
745746
"bigint" => Some("bigint"),
746747
"decimal" => Some("decimal"),
747748
"money" => Some("money"),
748749
"smallmoney" => Some("money"),
749750
"float" => Some("float"),
750751
"real" => Some("float"),
751752
"int64" => Some("bigint"),
752-
"int32" => Some("int"),
753-
"int16" => Some("int"),
753+
"int32" => Some("integer"),
754+
"int16" => Some("smallint"),
754755
_ => None,
755756
} {
756757
aggregate_functions.insert(
@@ -767,12 +768,12 @@ fn get_aggregate_functions_for_type(
767768
);
768769
};
769770

770-
aggregate_functions.insert(
771-
AggregateFunctionName::new("COUNT_BIG".into()),
772-
database::AggregateFunction {
773-
return_type: TypeName::new("bigint".to_string().into()),
774-
},
775-
);
771+
// aggregate_functions.insert(
772+
// AggregateFunctionName::new("COUNT_BIG".into()),
773+
// database::AggregateFunction {
774+
// return_type: TypeName::new("bigint".to_string().into()),
775+
// },
776+
// );
776777

777778
aggregate_functions
778779
}
@@ -787,14 +788,42 @@ fn get_scalar_types(type_names: &Vec<TypeItem>, schema_name: String) -> database
787788
Some(schema_name)
788789
};
789790

790-
for type_name in type_names {
791+
for type_item in type_names {
792+
let type_name = match type_item.name.as_str().to_lowercase().as_str() {
793+
"boolean" => "boolean",
794+
"int" => "integer",
795+
"int16" => "smallint",
796+
"smallint" => "smallint",
797+
"int32" => "integer",
798+
"integer" => "integer",
799+
"int64" => "bigint",
800+
"bigint" => "bigint",
801+
"numeric" => "numeric",
802+
"float64" => "float",
803+
"float" => "float",
804+
"real" => "real",
805+
"double precision" => "double precision",
806+
"text" => "text",
807+
"string" => "string",
808+
"character" => "character",
809+
"json" => "json",
810+
"jsonb" => "jsonb",
811+
"date" => "date",
812+
"time with time zone" => "time with time zone",
813+
"time without time zone" => "time without time zone",
814+
"timestamp with time zone" => "timestamp with time zone",
815+
"timestamp without time zone" => "timestamp without time zone",
816+
"uuid" => "uuid",
817+
_ => "any"
818+
};
819+
let type_name_scalar = ScalarTypeName::new(type_name.into());
791820
scalar_types.insert(
792-
type_name.name.clone(),
821+
type_name_scalar.clone(),
793822
database::ScalarType {
794-
type_name: type_name.name.clone(),
823+
type_name: type_name_scalar.clone(),
795824
schema_name: schema.clone(),
796-
comparison_operators: get_comparison_operators_for_type(&type_name.name),
797-
aggregate_functions: get_aggregate_functions_for_type(&type_name.name),
825+
comparison_operators: get_comparison_operators_for_type(&type_name_scalar),
826+
aggregate_functions: get_aggregate_functions_for_type(&type_name_scalar),
798827
description: None,
799828
type_representation: None,
800829
},

crates/query-engine/execution/src/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub async fn execute(
7373
parameter_value: Some(value),
7474
}
7575
}
76-
Param::Variable(_var) => todo!("Variables not implemented yet"),
76+
Param::Variable(_var) => todo!("Variables not implemented yet"), // error that `Err(Error::Query(QueryError::VariableNotFound(var.to_string())))`
7777
Param::Value(_value) => todo!("Values not implemented yet"), // todo(PY)
7878
})
7979
.collect(),

crates/query-engine/sql/src/sql/ast.rs

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use std::collections::BTreeMap;
44

5+
use serde_json::Number;
6+
57
/// An EXPLAIN clause
68
#[derive(Debug, Clone, PartialEq)]
79
pub enum Explain<'a> {
@@ -300,6 +302,10 @@ pub enum Expression {
300302
expression: Box<Expression>,
301303
nested_field: NestedField,
302304
},
305+
JoinExpressions(Vec<Expression>),
306+
SafeOffSet {
307+
offset: i32,
308+
},
303309
// JsonQuery(Box<Expression>, JsonPath), // JSON_QUERY([album].[json], '$.title') for multiple
304310
// // values
305311
// JsonValue(Box<Expression>, JsonPath), // JSON_VALUE([album].[json], '$.title') for single values
@@ -340,6 +346,7 @@ pub enum Function {
340346
ArrayAgg,
341347
Unnest,
342348
Unknown(String),
349+
SafeOffSet(String),
343350
}
344351

345352
/// COUNT clause
@@ -438,3 +445,10 @@ pub struct TableAlias {
438445
pub struct ColumnAlias {
439446
pub name: String,
440447
}
448+
449+
#[derive(Debug, Clone)]
450+
/// Whether this rows query returns fields or not.
451+
pub enum ReturnsFields {
452+
FieldsWereRequested,
453+
NoFieldsWereRequested,
454+
}

crates/query-engine/sql/src/sql/convert.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,17 @@ impl Expression {
469469
}
470470
sql.append_syntax(")");
471471
}
472+
Expression::JoinExpressions( expressions) => {
473+
for (index, expression) in expressions.iter().enumerate() {
474+
expression.to_sql(sql);
475+
if index < (expressions.len() - 1) {
476+
sql.append_syntax("")
477+
}
478+
}
479+
}
480+
Expression::SafeOffSet { offset } => {
481+
sql.append_syntax(format!("[SAFE_OFFSET({offset})]").as_str());
482+
}
472483
Expression::Exists { select } => {
473484
sql.append_syntax("EXISTS ");
474485
sql.append_syntax("(");
@@ -604,6 +615,7 @@ impl Function {
604615
Function::ArrayAgg => sql.append_syntax("ARRAY_AGG"),
605616
Function::Unnest => sql.append_syntax("unnest"),
606617
Function::Unknown(name) => sql.append_syntax(name),
618+
Function::SafeOffSet(index) => sql.append_syntax(format!("[SAFE_OFFSET({index})]").as_str()),
607619
}
608620
}
609621
}
@@ -736,9 +748,14 @@ impl TableName {
736748

737749
impl TableAlias {
738750
pub fn to_sql(&self, sql: &mut SQL) {
739-
let name = format!("{}_{}", self.name, self.unique_index);
751+
let name = self.to_string();
740752
sql.append_identifier(&name);
741753
}
754+
755+
pub fn to_string(&self) -> String {
756+
let name = format!("{}_{}", self.name, self.unique_index);
757+
name
758+
}
742759
}
743760

744761
impl ColumnReference {

0 commit comments

Comments
 (0)