Skip to content

Commit

Permalink
Research on timestamps (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyisaev2 authored Jan 31, 2025
1 parent 237a5fd commit 4d8b290
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/server/config/config.debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ logger:
metrics_server:
endpoint:
host: "0.0.0.0"
port: 8766
port: 8767

pprof_server:
endpoint:
Expand Down
11 changes: 11 additions & 0 deletions scripts/debug/kqprun/scheme.clickhouse.local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE OBJECT local_password (TYPE SECRET) WITH (value = "password");

CREATE EXTERNAL DATA SOURCE external_datasource WITH (
SOURCE_TYPE="ClickHouse",
LOCATION="localhost:9000",
AUTH_METHOD="BASIC",
PROTOCOL="NATIVE",
LOGIN="admin",
DATABASE_NAME="default",
PASSWORD_SECRET_NAME="local_password"
);
2 changes: 1 addition & 1 deletion scripts/debug/kqprun/scheme.mysql.local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CREATE OBJECT mysql_local_password (TYPE SECRET) WITH (value = "password");

CREATE EXTERNAL DATA SOURCE mysql_external_datasource WITH (
SOURCE_TYPE="MySQL",
LOCATION="mysql:3306",
LOCATION="localhost:3306",
AUTH_METHOD="BASIC",
LOGIN="root",
DATABASE_NAME="fq",
Expand Down
2 changes: 2 additions & 0 deletions scripts/debug/kqprun/script.clickhouse.local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--SELECT * FROM external_datasource.example_table WHERE datetimeValue = Timestamp("2023-12-31T15:00:00.000000Z");
SELECT * FROM external_datasource.example_table;
2 changes: 1 addition & 1 deletion scripts/debug/kqprun/script.mysql.local.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT * FROM mysql_external_datasource.simple;
SELECT * FROM mysql_external_datasource.datetimes;
3 changes: 2 additions & 1 deletion scripts/debug/kqprun/script.postgresql.local.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SELECT * FROM external_datasource.`datetime` WHERE col_01_timestamp = Timestamp("1988-11-20T12:55:28.123Z");
-- SELECT * FROM external_datasource.`datetime` WHERE col_01_timestamp = Timestamp("1988-11-20T12:55:28.123Z");
SELECT * FROM external_datasource.`datetime`;
11 changes: 5 additions & 6 deletions tools/clickhouse/timestamp_pushdown/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func main() {
createTableQuery := `
CREATE TABLE IF NOT EXISTS example_table (
id UInt32,
datetimeValue DateTime64(8, 'UTC')
datetimeValue DateTime64(8, 'Asia/Tokyo')
--datetimeValue DateTime64(8, 'UTC')
) ENGINE = MergeTree()
PRIMARY KEY id;`

Expand All @@ -56,7 +57,7 @@ func main() {
// 3. Insert some data into the table
insertQuery := `
INSERT INTO example_table (*) VALUES
(1, '1988-11-20 12:55:28.123456000')
(1, '2024-01-01 00:00:00.00000000')
`

_, err = db.ExecContext(ctx, insertQuery)
Expand All @@ -67,9 +68,7 @@ func main() {
fmt.Println("Data inserted successfully.")

// 4. Query the table with a filtering expression
timeValue := time.Date(1988, 11, 20, 12, 55, 28, 123456000, time.UTC)

rows, err := db.QueryContext(ctx, "SELECT id, datetimeValue FROM example_table WHERE datetimeValue = ?", timeValue)
rows, err := db.QueryContext(ctx, "SELECT id, datetimeValue FROM example_table")
if err != nil {
log.Fatalf("failed to execute query: %v", err)
}
Expand All @@ -88,7 +87,7 @@ func main() {
log.Fatalf("failed to scan row: %v", err)
}

fmt.Printf("ID: %d, DateTime: %s\n", id, datetimeValue.Format(time.RFC3339Nano))
fmt.Printf("ID: %d, DateTime: %v (%s)\n", id, datetimeValue, datetimeValue.Format(time.RFC3339Nano))
}

if err := rows.Err(); err != nil {
Expand Down

0 comments on commit 4d8b290

Please sign in to comment.