Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested_field_selector #20

Merged
merged 23 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b96987e
fix: add missing clickhouse column types to parser
BenoitRanque Jun 10, 2024
3c9eb95
add placeholder configuration for namespace separator. May expose as …
BenoitRanque Jun 10, 2024
b8ac7a6
utility function on identifier to extract underlying value
BenoitRanque Jun 10, 2024
ae8c872
hardcode period as namespace separator, for now
BenoitRanque Jun 10, 2024
fd23087
rework ClickHouseScalar type, use period separators and namespaces
BenoitRanque Jun 10, 2024
8041e3f
Use identifier value helper fn, separators
BenoitRanque Jun 10, 2024
0927ee0
formatting
BenoitRanque Jun 10, 2024
ff08356
add new error types
BenoitRanque Jun 10, 2024
c49193a
typecasting: support nested fields, leverage ClickHouseDataType inste…
BenoitRanque Jun 10, 2024
189546e
support nested field selectors and relationships
BenoitRanque Jun 10, 2024
aa14006
changelog, dependencies update
BenoitRanque Jun 10, 2024
6a854eb
add automated tests workflow
BenoitRanque Jun 10, 2024
501f7ff
add some sql generation tests for subfield selection
BenoitRanque Jun 10, 2024
79fa81a
bump version
BenoitRanque Jun 10, 2024
15313d8
fix formatting
BenoitRanque Jun 10, 2024
440dfe0
update ci job
BenoitRanque Jun 10, 2024
f628a96
test workflow: add comment explaining rustflag
BenoitRanque Jun 12, 2024
2995d81
fix order_by across relationships bug
BenoitRanque Jun 12, 2024
496a6ea
fix issue with native query data types
BenoitRanque Jun 12, 2024
923cbab
add more tests
BenoitRanque Jun 12, 2024
e548de4
restore group by when ordering by column
BenoitRanque Jun 12, 2024
4614e7e
add variables tests
BenoitRanque Jun 13, 2024
2cb8bde
update tests for group by change
BenoitRanque Jun 13, 2024
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
28 changes: 28 additions & 0 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Test Suite"
on:
pull_request:

jobs:
test:
name: cargo test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""
- run: cargo test --all-features

# Check formatting with rustfmt
formatting:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Ensure rustfmt is installed and setup problem matcher
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
rustflags: ""
- name: Rustfmt Check
uses: actions-rust-lang/rustfmt@v1
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.9]

- Change namespaceing to use `.` separator instead of `_`. We assume table names are less likely to contain periods, so this reduces likelyhood of naming conflicts.This will change generated type names and will thus manifest as a breaking change for some users
- Support `Nested` column types correctly, (previously these were treated as essentially Tuple columns)
- Support subfield selection on complex column types.
- Add support for relationships on column subfields, if the path to the subfield does not include lists
- Fix datatype parser: add ability to parse SimpleAggregateFunction and AggregateFunction columns

## [0.2.8]

- Make spans visible to cloud console users (tag spans with `internal.visibility = 'user'`)
Expand Down
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ members = [
]
resolver = "2"

package.version = "0.2.8"
package.version = "0.2.9"
package.edition = "2021"
12 changes: 12 additions & 0 deletions crates/common/src/clickhouse_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ peg::parser! {
/ map()
/ tuple()
/ r#enum()
/ aggregate_function()
/ simple_aggregate_function()
/ nothing()
rule nullable() -> DT = "Nullable(" t:data_type() ")" { DT::Nullable(Box::new(t)) }
rule uint8() -> DT = "UInt8" { DT::UInt8 }
Expand Down Expand Up @@ -181,6 +183,16 @@ fn can_parse_clickhouse_data_type() {
(Some(Identifier::BacktickQuoted("u".to_string())), DT::UInt8),
]),
),
(
"SimpleAggregateFunction(sum, UInt64)",
DT::SimpleAggregateFunction {
function: AggregateFunctionDefinition {
name: Identifier::Unquoted("sum".to_string()),
parameters: None,
},
arguments: vec![DT::UInt64],
},
),
];

for (s, t) in data_types {
Expand Down
10 changes: 10 additions & 0 deletions crates/common/src/clickhouse_parser/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ pub enum Identifier {
Unquoted(String),
}

impl Identifier {
pub fn value(&self) -> &str {
match self {
Identifier::DoubleQuoted(s)
| Identifier::BacktickQuoted(s)
| Identifier::Unquoted(s) => s,
}
}
}

impl Display for Identifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
1 change: 1 addition & 0 deletions crates/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
pub struct ServerConfig {
/// the connection part of the config is not part of the config file
pub connection: ConnectionConfig,
pub namespace_separator: String,
pub table_types: BTreeMap<ReturnTypeRef, TableType>,
pub tables: BTreeMap<String, TableConfig>,
pub queries: BTreeMap<String, ParameterizedQueryConfig>,
Expand Down
1 change: 1 addition & 0 deletions crates/ndc-clickhouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ reqwest = { version = "0.12.3", features = [
"json",
"rustls-tls",
], default-features = false }
schemars = "0.8.16"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
sqlformat = "0.2.3"
Expand Down
3 changes: 3 additions & 0 deletions crates/ndc-clickhouse/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ pub async fn read_server_config(

let config = ServerConfig {
connection,
// hardcoding separator for now, to avoid prematurely exposing configuration options we may not want to keep
// if we make this configurable, we must default to this separator when the option is not provided
namespace_separator: ".".to_string(),
table_types,
tables,
queries,
Expand Down
6 changes: 1 addition & 5 deletions crates/ndc-clickhouse/src/connector/handler/query.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use common::{client::execute_query, config::ServerConfig};
use ndc_sdk::{
connector::QueryError,
json_response::JsonResponse,
models::{self, QueryResponse},
};
use ndc_sdk::{connector::QueryError, json_response::JsonResponse, models};
use tracing::{Instrument, Level};

use crate::{connector::state::ServerState, sql::QueryBuilder};
Expand Down
23 changes: 9 additions & 14 deletions crates/ndc-clickhouse/src/connector/handler/schema.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::schema::ClickHouseTypeDefinition;
use common::{
clickhouse_parser::{
datatype::{ClickHouseDataType, Identifier},
datatype::ClickHouseDataType,
parameterized_query::{Parameter, ParameterType, ParameterizedQueryElement},
},
config::ServerConfig,
Expand All @@ -23,6 +23,7 @@ pub async fn schema(
&column_type,
&column_alias,
&type_name,
&configuration.namespace_separator,
);

let (scalars, objects) = type_definition.type_definitions();
Expand Down Expand Up @@ -61,6 +62,7 @@ pub async fn schema(
&argument_type,
&argument_name,
table_alias,
&configuration.namespace_separator,
);
let (scalars, objects) = type_definition.type_definitions();

Expand All @@ -79,19 +81,15 @@ pub async fn schema(
for (query_alias, query_config) in &configuration.queries {
for element in &query_config.query.elements {
if let ParameterizedQueryElement::Parameter(Parameter { name, r#type }) = element {
let argument_alias = match name {
Identifier::DoubleQuoted(n)
| Identifier::BacktickQuoted(n)
| Identifier::Unquoted(n) => n,
};
let data_type = match r#type {
ParameterType::Identifier => &ClickHouseDataType::String,
ParameterType::DataType(t) => t,
};
let type_definition = ClickHouseTypeDefinition::from_query_argument(
data_type,
&argument_alias,
name.value(),
query_alias,
&configuration.namespace_separator,
);

let (scalars, objects) = type_definition.type_definitions();
Expand Down Expand Up @@ -123,6 +121,7 @@ pub async fn schema(
&argument_type,
&argument_name,
table_alias,
&configuration.namespace_separator,
);
(
argument_name.to_owned(),
Expand Down Expand Up @@ -164,23 +163,19 @@ pub async fn schema(
.filter_map(|element| match element {
ParameterizedQueryElement::String(_) => None,
ParameterizedQueryElement::Parameter(Parameter { name, r#type }) => {
let argument_alias = match name {
Identifier::DoubleQuoted(n)
| Identifier::BacktickQuoted(n)
| Identifier::Unquoted(n) => n,
};
let data_type = match r#type {
ParameterType::Identifier => &ClickHouseDataType::String,
ParameterType::DataType(t) => &t,
};
let type_definition = ClickHouseTypeDefinition::from_query_argument(
data_type,
&argument_alias,
name.value(),
query_alias,
&configuration.namespace_separator,
);

Some((
argument_alias.to_owned(),
name.value().to_owned(),
models::ArgumentInfo {
description: None,
argument_type: type_definition.type_identifier(),
Expand Down
Loading