From 3f4a60e0200aed1174b6003980a32becf4d218ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Tue, 23 Jan 2024 16:45:51 -0500 Subject: [PATCH] fix clickhouse tutorial and timestamp parsing, bump v4.0.0 --- CHANGELOG.md | 4 +++- db/dialect_clickhouse.go | 8 +++++++- docs/tutorial/schema-clickhouse.sql | 17 ----------------- docs/tutorial/schema.clickhouse.sql | 8 ++++++++ ...ickhouse.yaml => substreams.clickhouse.yaml} | 3 +-- 5 files changed, 19 insertions(+), 21 deletions(-) delete mode 100644 docs/tutorial/schema-clickhouse.sql create mode 100644 docs/tutorial/schema.clickhouse.sql rename docs/tutorial/{substreams-clickhouse.yaml => substreams.clickhouse.yaml} (95%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22024cc..e5d7299 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +* Fixed the timestamp parsing in Clickhouse dialect. +* Fixed the schema in the tutorial for clickhouse. * Bump version of `schema` dependency to fix errors with new Clickhouse versions now using `system.tables` table instead of `information_schema.tables` view. * Add `--network` flag to override the default value in the manifest or spkg -## v4.0.0-rc.3 +## v4.0.0 * Fix a critical bug breaking the reorg management when more than one row needs to be reverted. diff --git a/db/dialect_clickhouse.go b/db/dialect_clickhouse.go index 11b9231..6387c1a 100644 --- a/db/dialect_clickhouse.go +++ b/db/dialect_clickhouse.go @@ -227,7 +227,13 @@ func convertToType(value string, valueType reflect.Type) (any, error) { return int64(i), nil } - v, err := time.Parse("2006-01-02T15:04:05Z", value) + var v time.Time + var err error + if strings.Contains(value, "T") && strings.HasSuffix(value, "Z") { + v, err = time.Parse("2006-01-02T15:04:05Z", value) + } else { + v, err = time.Parse("2006-01-02 15:04:05", value) + } if err != nil { return "", fmt.Errorf("could not convert %s to time: %w", value, err) } diff --git a/docs/tutorial/schema-clickhouse.sql b/docs/tutorial/schema-clickhouse.sql deleted file mode 100644 index 6fcd402..0000000 --- a/docs/tutorial/schema-clickhouse.sql +++ /dev/null @@ -1,17 +0,0 @@ -create table block_meta -( - id text not null constraint block_meta_pk primary key, - at timestamp, - number bigint, - hash text, - parent_hash text, - timestamp timestamp -); - -create table cursors -( - id text not null constraint cursor_pk primary key, - cursor text, - block_num bigint, - block_id text -); \ No newline at end of file diff --git a/docs/tutorial/schema.clickhouse.sql b/docs/tutorial/schema.clickhouse.sql new file mode 100644 index 0000000..a591081 --- /dev/null +++ b/docs/tutorial/schema.clickhouse.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS block_meta ( + "id" VARCHAR(64), + "at" VARCHAR(64), + "number" UInt64, + "hash" VARCHAR(64), + "parent_hash" VARCHAR(64), + "timestamp" VARCHAR(64), +) ENGINE = MergeTree PRIMARY KEY ("id"); diff --git a/docs/tutorial/substreams-clickhouse.yaml b/docs/tutorial/substreams.clickhouse.yaml similarity index 95% rename from docs/tutorial/substreams-clickhouse.yaml rename to docs/tutorial/substreams.clickhouse.yaml index da34169..06f9e34 100644 --- a/docs/tutorial/substreams-clickhouse.yaml +++ b/docs/tutorial/substreams.clickhouse.yaml @@ -40,8 +40,7 @@ sink: module: db_out type: sf.substreams.sink.sql.v1.Service config: - schema: "./schema.sql" - wire_protocol_access: true + schema: "./schema.clickhouse.sql" engine: clickhouse postgraphile_frontend: enabled: false