Skip to content

Commit 2a2cc92

Browse files
committed
remove unused imports/variables
1 parent 9922302 commit 2a2cc92

File tree

20 files changed

+212
-666
lines changed

20 files changed

+212
-666
lines changed

crates/cli/src/lib.rs

-12
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,12 @@ pub async fn run(command: Command, context: Context<impl Environment>) -> anyhow
7272
/// Optionally, this can also create the connector metadata, which is used by the Hasura CLI to
7373
/// automatically work with this CLI as a plugin.
7474
async fn initialize(with_metadata: bool, context: Context<impl Environment>) -> anyhow::Result<()> {
75-
let configuration_file = context
76-
.context_path
77-
.join(configuration::version1::CONFIGURATION_FILENAME);
78-
fs::create_dir_all(&context.context_path).await?;
79-
8075
// refuse to initialize the directory unless it is empty
8176
let mut items_in_dir = fs::read_dir(&context.context_path).await?;
8277
if items_in_dir.next_entry().await?.is_some() {
8378
Err(Error::DirectoryIsNotEmpty)?;
8479
}
8580

86-
// // create the configuration file
87-
// fs::write(
88-
// configuration_file,
89-
// serde_json::to_string_pretty(&configuration::ParsedConfiguration::empty())? + "\n",
90-
// )
91-
// .await?;
92-
9381
configuration::write_parsed_configuration(
9482
configuration::ParsedConfiguration::initial(),
9583
&context.context_path,

crates/configuration/src/configuration.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
//! Configuration for the connector.
22
3-
use std::path::Path;
4-
53
use query_engine_metadata::metadata;
64

7-
use crate::environment::Environment;
8-
use crate::error::{
9-
MakeRuntimeConfigurationError, MultiError, ParseConfigurationError,
10-
WriteParsedConfigurationError,
11-
};
125
use crate::values::PoolSettings;
13-
use schemars::{gen::SchemaSettings, schema::RootSchema};
146

157
/// The 'Configuration' type collects all the information necessary to serve queries at runtime.
168
///

crates/configuration/src/to_runtime_configuration.rs

+34-34
Original file line numberDiff line numberDiff line change
@@ -326,42 +326,42 @@ fn convert_operator_kind(
326326
}
327327
}
328328

329-
fn convert_composite_types(
330-
composite_types: metadata::CompositeTypes,
331-
) -> query_engine_metadata::metadata::CompositeTypes {
332-
query_engine_metadata::metadata::CompositeTypes(
333-
composite_types
334-
.0
335-
.into_iter()
336-
.map(|(k, composite_type)| (k, convert_composite_type(composite_type)))
337-
.collect(),
338-
)
339-
}
329+
// fn convert_composite_types(
330+
// composite_types: metadata::CompositeTypes,
331+
// ) -> query_engine_metadata::metadata::CompositeTypes {
332+
// query_engine_metadata::metadata::CompositeTypes(
333+
// composite_types
334+
// .0
335+
// .into_iter()
336+
// .map(|(k, composite_type)| (k, convert_composite_type(composite_type)))
337+
// .collect(),
338+
// )
339+
// }
340340

341-
fn convert_composite_type(
342-
composite_type: metadata::CompositeType,
343-
) -> query_engine_metadata::metadata::CompositeType {
344-
query_engine_metadata::metadata::CompositeType {
345-
type_name: composite_type.type_name,
346-
schema_name: (composite_type.schema_name),
347-
fields: composite_type
348-
.fields
349-
.into_iter()
350-
.map(|(k, field)| (k, convert_composite_type_field_info(field)))
351-
.collect(),
352-
description: composite_type.description,
353-
}
354-
}
341+
// fn convert_composite_type(
342+
// composite_type: metadata::CompositeType,
343+
// ) -> query_engine_metadata::metadata::CompositeType {
344+
// query_engine_metadata::metadata::CompositeType {
345+
// type_name: composite_type.type_name,
346+
// schema_name: (composite_type.schema_name),
347+
// fields: composite_type
348+
// .fields
349+
// .into_iter()
350+
// .map(|(k, field)| (k, convert_composite_type_field_info(field)))
351+
// .collect(),
352+
// description: composite_type.description,
353+
// }
354+
// }
355355

356-
fn convert_composite_type_field_info(
357-
field: metadata::FieldInfo,
358-
) -> query_engine_metadata::metadata::FieldInfo {
359-
query_engine_metadata::metadata::FieldInfo {
360-
field_name: field.field_name,
361-
r#type: convert_type(field.r#type),
362-
description: field.description,
363-
}
364-
}
356+
// fn convert_composite_type_field_info(
357+
// field: metadata::FieldInfo,
358+
// ) -> query_engine_metadata::metadata::FieldInfo {
359+
// query_engine_metadata::metadata::FieldInfo {
360+
// field_name: field.field_name,
361+
// r#type: convert_type(field.r#type),
362+
// description: field.description,
363+
// }
364+
// }
365365

366366
pub fn convert_tables(tables: metadata::TablesInfo) -> query_engine_metadata::metadata::TablesInfo {
367367
query_engine_metadata::metadata::TablesInfo(

crates/configuration/src/version1.rs

+3-68
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,23 @@
22
33
use crate::environment::Environment;
44
use crate::error::WriteParsedConfigurationError;
5-
use crate::values::{self, ConnectionUri, DatasetId, PoolSettings, ProjectId, Secret};
5+
use crate::values::{ConnectionUri, DatasetId, PoolSettings, ProjectId, Secret};
66

77
use super::error::ParseConfigurationError;
8-
use gcp_bigquery_client::model::job_configuration_query::JobConfigurationQuery;
9-
use gcp_bigquery_client::model::query_parameter::QueryParameter;
10-
use gcp_bigquery_client::model::query_parameter_type::QueryParameterType;
11-
use gcp_bigquery_client::model::query_parameter_value::QueryParameterValue;
128
use gcp_bigquery_client::model::query_request::QueryRequest;
13-
use gcp_bigquery_client::project;
149
use ndc_models::{AggregateFunctionName, ComparisonOperatorName, ScalarTypeName, TypeName};
15-
use schemars::{schema, JsonSchema};
10+
use schemars::JsonSchema;
1611
use serde::{Deserialize, Serialize};
17-
use sqlx::postgres::PgConnection;
18-
use sqlx::{Connection, Executor, Row};
1912
use std::borrow::Cow;
2013
use std::collections::BTreeMap;
21-
use std::fmt::format;
2214
use std::path::Path;
2315
use thiserror::Error;
2416
use tokio::fs;
25-
use tracing::{info_span, Instrument};
2617

2718
//TODO(PY): temp, needs to be removed from the crate
2819
// use ndc_sdk::connector;
2920

30-
use query_engine_metadata::metadata::{
31-
self, database, CompositeTypes, ScalarTypeTypeName, ScalarTypes, TablesInfo,
32-
};
21+
use query_engine_metadata::metadata::{self, database, TablesInfo};
3322

3423
const CURRENT_VERSION: u32 = 1;
3524
pub const CONFIGURATION_FILENAME: &str = "configuration.json";
@@ -57,15 +46,6 @@ const APPROX_NUMERICS: [&str; 3] = ["float", "real", "float64"];
5746
const NOT_COUNTABLE: [&str; 3] = ["image", "ntext", "text"];
5847
const NOT_APPROX_COUNTABLE: [&str; 4] = ["image", "sql_variant", "ntext", "text"];
5948

60-
// const TYPES_QUERY: &str =
61-
// format!("select data_type from {}.INFORMATION_SCHEMA.COLUMN_FIELD_PATHS");
62-
63-
// const DATA: &str = "chinook_sample";
64-
65-
const TYPES_QUERY1: &str =
66-
"select data_type from @dataset_id.INFORMATION_SCHEMA.COLUMN_FIELD_PATHS";
67-
const TYPES_QUERY2: &str = "select data_type from @dataset.INFORMATION_SCHEMA.COLUMN_FIELD_PATHS";
68-
6949
/// Initial configuration, just enough to connect to a database and elaborate a full
7050
/// 'Configuration'.
7151
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
@@ -123,22 +103,6 @@ pub enum SingleOrList<T> {
123103
List(Vec<T>),
124104
}
125105

126-
impl<T: Clone> SingleOrList<T> {
127-
fn is_empty(&self) -> bool {
128-
match self {
129-
SingleOrList::Single(_) => false,
130-
SingleOrList::List(l) => l.is_empty(),
131-
}
132-
}
133-
134-
fn to_vec(&self) -> Vec<T> {
135-
match self {
136-
SingleOrList::Single(s) => vec![s.clone()],
137-
SingleOrList::List(l) => l.clone(),
138-
}
139-
}
140-
}
141-
142106
// #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
143107
// #[serde(untagged)]
144108
// pub enum ConnectionUris {
@@ -672,20 +636,6 @@ struct TypeItem {
672636
name: ScalarTypeName,
673637
}
674638

675-
// we lookup all types in sys.types, then use our hardcoded ideas about each one to attach
676-
// aggregate functions
677-
fn get_aggregate_functions(type_names: &Vec<TypeItem>) -> database::AggregateFunctions {
678-
let mut aggregate_functions = BTreeMap::new();
679-
680-
for type_name in type_names {
681-
aggregate_functions.insert(
682-
type_name.name.clone(),
683-
get_aggregate_functions_for_type(&type_name.name),
684-
);
685-
}
686-
database::AggregateFunctions(aggregate_functions)
687-
}
688-
689639
// we hard code these, essentially
690640
// we look up available types in `sys.types` but hard code their behaviour by looking them up below
691641
// taken from https://learn.microsoft.com/en-us/sql/t-sql/functions/aggregate-functions-transact-sql?view=sql-server-ver16
@@ -859,21 +809,6 @@ fn get_scalar_types(type_names: &Vec<TypeItem>, schema_name: String) -> database
859809
database::ScalarTypes(scalar_types)
860810
}
861811

862-
// we lookup all types in sys.types, then use our hardcoded ideas about each one to attach
863-
// comparison operators
864-
fn get_comparison_operators(type_names: &Vec<TypeItem>) -> database::ComparisonOperators {
865-
let mut comparison_operators = BTreeMap::new();
866-
867-
for type_name in type_names {
868-
comparison_operators.insert(
869-
type_name.name.clone(),
870-
get_comparison_operators_for_type(&type_name.name),
871-
);
872-
}
873-
874-
database::ComparisonOperators(comparison_operators)
875-
}
876-
877812
// we hard code these, essentially
878813
// we look up available types in `sys.types` but hard code their behaviour by looking them up below
879814
// categories taken from https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
WITH column_data AS (
2+
SELECT
3+
t.table_name,
4+
t.table_catalog,
5+
t.table_schema,
6+
c.column_name,
7+
TO_JSON_STRING(STRUCT(
8+
c.column_name AS name,
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,
37+
CASE WHEN c.is_nullable = 'YES' THEN 'nullable' ELSE 'nonNullable' END AS nullable
38+
)) AS column_info
39+
FROM hasura_database_name.INFORMATION_SCHEMA.TABLES AS t
40+
JOIN hasura_database_name.INFORMATION_SCHEMA.COLUMNS AS c
41+
ON c.table_catalog = t.table_catalog
42+
AND c.table_schema = t.table_schema
43+
AND c.table_name = t.table_name
44+
WHERE t.table_schema = 'chinook_sample'
45+
),
46+
columns_struct AS (
47+
SELECT
48+
table_name,
49+
table_catalog,
50+
table_schema,
51+
STRUCT(
52+
STRING_AGG(
53+
CONCAT('"', column_name, '":', column_info),
54+
','
55+
) AS columns_json
56+
) AS columns
57+
FROM column_data
58+
GROUP BY table_name, table_catalog, table_schema
59+
),
60+
relationship_data AS (
61+
SELECT
62+
t.table_name,
63+
t.table_catalog,
64+
t.table_schema,
65+
c.constraint_name,
66+
TO_JSON_STRING(STRUCT(
67+
rc.table_name AS foreign_table,
68+
json_object(fc.column_name, rc.column_name) as column_mapping
69+
)) AS relationship_info
70+
FROM hasura_database_name.INFORMATION_SCHEMA.TABLES AS t
71+
JOIN hasura_database_name.INFORMATION_SCHEMA.TABLE_CONSTRAINTS as c
72+
ON c.table_catalog = t.table_catalog
73+
AND c.table_schema = t.table_schema
74+
AND c.table_name = t.table_name
75+
JOIN hasura_database_name.INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE as rc
76+
ON c.constraint_catalog = rc.constraint_catalog
77+
AND c.constraint_schema = rc.constraint_schema
78+
AND c.constraint_name = rc.constraint_name
79+
JOIN hasura_database_name.INFORMATION_SCHEMA.KEY_COLUMN_USAGE as fc ON c.constraint_name = fc.constraint_name
80+
WHERE t.table_schema = 'chinook_sample' AND c.constraint_type = 'FOREIGN KEY'
81+
GROUP BY t.table_name, table_catalog, table_schema, constraint_name, rc.table_name, fc.column_name, rc.column_name
82+
),
83+
relationship_struct AS (
84+
SELECT
85+
table_name,
86+
table_catalog,
87+
table_schema,
88+
STRUCT(
89+
STRING_AGG(
90+
CONCAT('"', constraint_name, '":', relationship_info),
91+
','
92+
) AS relationships_json
93+
) AS relationships
94+
FROM relationship_data
95+
GROUP BY table_name, table_catalog, table_schema
96+
),
97+
unique_constraint_data AS (
98+
SELECT
99+
t.table_name,
100+
t.table_catalog,
101+
t.table_schema,
102+
c.constraint_name,
103+
TO_JSON_STRING(JSON_ARRAY(cc.column_name)) AS unique_constraint_info
104+
FROM hasura_database_name.INFORMATION_SCHEMA.TABLES AS t
105+
JOIN hasura_database_name.INFORMATION_SCHEMA.TABLE_CONSTRAINTS as c
106+
ON c.table_catalog = t.table_catalog
107+
AND c.table_schema = t.table_schema
108+
AND c.table_name = t.table_name
109+
JOIN hasura_database_name.INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE as cc
110+
ON c.constraint_name = cc.constraint_name
111+
WHERE t.table_schema = 'chinook_sample'
112+
AND c.constraint_type in ('PRIMARY KEY', 'UNIQUE')
113+
AND cc.constraint_catalog = c.constraint_catalog
114+
AND cc.constraint_schema = c.constraint_schema
115+
),
116+
unique_constraint_struct AS (
117+
SELECT
118+
table_name,
119+
table_catalog,
120+
table_schema,
121+
STRUCT(
122+
STRING_AGG(
123+
CONCAT('"', constraint_name, '":', unique_constraint_info),
124+
','
125+
) AS unique_constraint_json
126+
) AS unique_constraint
127+
FROM unique_constraint_data
128+
GROUP BY table_name, table_catalog, table_schema
129+
)
130+
SELECT
131+
CONCAT('{', STRING_AGG(CONCAT(
132+
'"', columns_struct.table_name, '": {',
133+
'"schemaName": ',
134+
'"', CONCAT(columns_struct.table_catalog , '.', columns_struct.table_schema), '", ',
135+
'"tableName": ' , '"', columns_struct.table_name, '", '
136+
'"columns": {',
137+
columns_struct.columns.columns_json,
138+
'},',
139+
'"uniquenessConstraints": {',
140+
coalesce(unique_constraint_struct.unique_constraint.unique_constraint_json, ""),
141+
'},',
142+
'"foreignRelations": {',
143+
coalesce(relationship_struct.relationships.relationships_json, ""),
144+
'}'
145+
'}'
146+
)), '}') AS result
147+
FROM columns_struct
148+
LEFT JOIN relationship_struct ON columns_struct.table_name = relationship_struct.table_name
149+
LEFT JOIN unique_constraint_struct ON columns_struct.table_name = unique_constraint_struct.table_name

0 commit comments

Comments
 (0)