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

Update-errors #22

Merged
merged 13 commits into from
Aug 2, 2024
7 changes: 7 additions & 0 deletions .github/workflows/deploy-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ jobs:
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
steps:
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: "" # defaults to "-D warnings", set to empty string to allow warnings

- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
Expand Down Expand Up @@ -183,6 +187,9 @@ jobs:

mkdir -p "${ROOT}/release/connector-definition/.hasura-connector/"
cat "${ROOT}/ci/templates/connector-metadata.yaml" | envsubst > "${ROOT}/release/connector-definition/.hasura-connector/connector-metadata.yaml"

cargo run --package ndc-clickhouse-cli -- --connector-context-path "${ROOT}/release/connector-definition" init

tar -czvf "${ROOT}/release/artifacts/connector-definition.tgz" --directory "${ROOT}/release/connector-definition/" .

- uses: actions/upload-artifact@v4
Expand Down
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.10]

- Correct CLI implementation of Init command (used to behave the same as update)
- Update sdk & errors
- Fix version returned by capabilities
- Fix parameter escaping, enabling complex data types as parameters
- Remove deprecated JSON data type, see [clickhouse docs](https://clickhouse.com/docs/en/sql-reference/data-types/object-data-type)

## [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
Expand Down
10 changes: 5 additions & 5 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.9"
package.version = "0.2.10"
package.edition = "2021"
2 changes: 0 additions & 2 deletions crates/common/src/clickhouse_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ peg::parser! {
/ date_time()
/ date32()
/ date()
/ json()
/ uuid()
/ ipv4()
/ ipv6()
Expand Down Expand Up @@ -86,7 +85,6 @@ peg::parser! {
rule date32() -> DT = "Date32" { DT::Date32 }
rule date_time() -> DT = "DateTime" tz:("(" tz:single_quoted_string_value()? ")" { tz })? { DT::DateTime { timezone: tz.flatten().map(|s| s.to_owned()) } }
rule date_time64() -> DT = "DateTime64(" precision:integer_value() tz:(comma_separator() tz:single_quoted_string_value()? { tz })? ")" { DT::DateTime64{ precision, timezone: tz.flatten().map(|s| s.to_owned())} }
rule json() -> DT = "JSON" { DT::Json }
rule uuid() -> DT = "UUID" { DT::Uuid }
rule ipv4() -> DT = "IPv4" { DT::IPv4 }
rule ipv6() -> DT = "IPv6" { DT::IPv6 }
Expand Down
4 changes: 1 addition & 3 deletions crates/common/src/clickhouse_parser/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Display for AggregateFunctionParameter {

/// A parsed representation of a clickhouse datatype string
/// This should support the full scope of clickhouse types
/// To create one from a string slice, use try_from()
/// To create one from a string slice, use from_str()
#[derive(Debug, Clone, PartialEq)]
pub enum ClickHouseDataType {
Nullable(Box<ClickHouseDataType>),
Expand Down Expand Up @@ -133,7 +133,6 @@ pub enum ClickHouseDataType {
precision: u32,
timezone: Option<SingleQuotedString>,
},
Json,
Uuid,
IPv4,
IPv6,
Expand Down Expand Up @@ -203,7 +202,6 @@ impl Display for ClickHouseDataType {
}
write!(f, ")")
}
DT::Json => write!(f, "JSON"),
DT::Uuid => write!(f, "UUID"),
DT::IPv4 => write!(f, "IPv4"),
DT::IPv6 => write!(f, "IPv6"),
Expand Down
12 changes: 11 additions & 1 deletion crates/common/src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
/// the main configuration file
pub struct ServerConfigFile {
#[serde(rename = "$schema")]
Expand All @@ -22,6 +22,16 @@ pub struct ServerConfigFile {
pub queries: BTreeMap<String, ParameterizedQueryConfigFile>,
}

impl Default for ServerConfigFile {
fn default() -> Self {
Self {
schema: CONFIG_SCHEMA_FILE_NAME.to_string(),
tables: Default::default(),
queries: Default::default(),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct TableConfigFile {
/// The table name
Expand Down
3 changes: 3 additions & 0 deletions crates/ndc-clickhouse-cli/src/database_introspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ use common::{
pub struct TableInfo {
pub table_name: String,
pub table_schema: String,
#[allow(dead_code)]
pub table_catalog: String,
pub table_comment: Option<String>,
#[allow(dead_code)]
pub table_type: TableType,
pub primary_key: Option<String>,
pub view_definition: String,
Expand All @@ -23,6 +25,7 @@ pub struct TableInfo {
pub struct ColumnInfo {
pub column_name: String,
pub data_type: String,
#[allow(dead_code)]
pub is_nullable: bool,
pub is_in_primary_key: bool,
}
Expand Down
76 changes: 40 additions & 36 deletions crates/ndc-clickhouse-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,25 @@ struct CliArgs {
env = "HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH"
)]
context_path: Option<PathBuf>,
#[arg(long = "clickhouse-url", value_name = "URL", env = "CLICKHOUSE_URL")]
clickhouse_url: String,
#[arg(long = "clickhouse-username", value_name = "USERNAME", env = "CLICKHOUSE_USERNAME", default_value_t = String::from("default"))]
clickhouse_username: String,
#[arg(
long = "clickhouse-password",
value_name = "PASSWORD",
env = "CLICKHOUSE_PASSWORD"
)]
clickhouse_password: String,
#[command(subcommand)]
command: Command,
}

#[derive(Clone, Subcommand)]
enum Command {
Init {},
Update {},
Update {
#[arg(long = "clickhouse-url", value_name = "URL", env = "CLICKHOUSE_URL")]
url: String,
#[arg(long = "clickhouse-username", value_name = "USERNAME", env = "CLICKHOUSE_USERNAME", default_value_t = String::from("default"))]
username: String,
#[arg(
long = "clickhouse-password",
value_name = "PASSWORD",
env = "CLICKHOUSE_PASSWORD"
)]
password: String,
},
Validate {},
Watch {},
}
Expand All @@ -93,11 +94,6 @@ enum LogLevel {
Trace,
}

struct Context {
context_path: PathBuf,
connection: ConnectionConfig,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let args = CliArgs::parse();
Expand All @@ -107,33 +103,41 @@ async fn main() -> Result<(), Box<dyn Error>> {
Some(path) => path,
};

let connection = ConnectionConfig {
url: args.clickhouse_url,
username: args.clickhouse_username,
password: args.clickhouse_password,
};

let context = Context {
context_path,
connection,
};

match args.command {
Command::Init {} => {
let introspection = introspect_database(&context.connection).await?;
let config = update_tables_config(&context.context_path, &introspection).await?;
validate_table_config(&context.context_path, &config).await?;
let config = ServerConfigFile::default();
let config_schema = schema_for!(ServerConfigFile);

let file_path = context_path.join(CONFIG_FILE_NAME);
let schema_file_path = context_path.join(CONFIG_SCHEMA_FILE_NAME);

fs::write(&file_path, serde_json::to_string_pretty(&config)?).await?;
fs::write(
&schema_file_path,
serde_json::to_string_pretty(&config_schema)?,
)
.await?;
}
Command::Update {} => {
let introspection = introspect_database(&context.connection).await?;
let config = update_tables_config(&context.context_path, &introspection).await?;
validate_table_config(&context.context_path, &config).await?;
Command::Update {
url,
username,
password,
} => {
let connection = ConnectionConfig {
url,
username,
password,
};

let introspection = introspect_database(&connection).await?;
let config = update_tables_config(&context_path, &introspection).await?;
validate_table_config(&context_path, &config).await?;
}
Command::Validate {} => {
let file_path = context.context_path.join(CONFIG_FILE_NAME);
let file_path = context_path.join(CONFIG_FILE_NAME);
let config = read_config_file(&file_path).await?;
if let Some(config) = config {
validate_table_config(&context.context_path, &config).await?;
validate_table_config(&context_path, &config).await?;
}
}
Command::Watch {} => {
Expand Down
2 changes: 1 addition & 1 deletion crates/ndc-clickhouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async-trait = "0.1.78"
bytes = "1.6.0"
common = { path = "../common" }
indexmap = "2.1.0"
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs", tag = "v0.1.4", package = "ndc-sdk" }
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs", tag = "v0.1.5", package = "ndc-sdk" }
prometheus = "0.13.3"
reqwest = { version = "0.12.3", features = [
"json",
Expand Down
Loading