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

fix: timescaledb&clickhouse bench #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 9 additions & 4 deletions pkg/targets/clickhouse/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ func createMetricsTable(conf *ClickhouseConfig, db *sqlx.DB, tableName string, f
tags_id UInt32,
%s,
additional_tags String DEFAULT ''
) ENGINE = MergeTree(created_date, (tags_id, created_at), 8192)
) ENGINE = MergeTree()
ORDER BY (tags_id, created_at, created_date)
PRIMARY KEY (tags_id, created_at)
`,
tableName,
strings.Join(columnsWithType, ","))
if conf.Debug > 0 {
fmt.Printf(sql)
fmt.Print(sql)
}
_, err := db.Exec(sql)
if err != nil {
Expand All @@ -174,15 +176,18 @@ func generateTagsTableQuery(tagNames, tagTypes []string) string {

index := "id"

return fmt.Sprintf(
var fullCreateTableCmd = fmt.Sprintf(
"CREATE TABLE tags(\n"+
"created_date Date DEFAULT today(),\n"+
"created_at DateTime DEFAULT now(),\n"+
"id UInt32,\n"+
"%s"+
") ENGINE = MergeTree(created_date, (%s), 8192)",
")\nENGINE = MergeTree()\n"+
"ORDER BY (created_date, %s)",
cols,
index)
fmt.Println("Create table query: ", fullCreateTableCmd)
return fullCreateTableCmd
}

func serializedTypeToClickHouseType(serializedType string) string {
Expand Down
19 changes: 16 additions & 3 deletions pkg/targets/timescaledb/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,22 @@ func (d *dbCreator) createTableAndIndexes(dbBench *sql.DB, tableName string, fie
partitionsOption = fmt.Sprintf("partitioning_column => '%s'::name, replication_factor => %v::smallint", partitionColumn, d.opts.ReplicationFactor)
}

MustExec(dbBench,
fmt.Sprintf("SELECT %s('%s'::regclass, 'time'::name, %s, chunk_time_interval => %d, create_default_indexes=>FALSE)",
creationCommand, tableName, partitionsOption, d.opts.ChunkTime.Nanoseconds()/1000))
var chunkTimeInterval = d.opts.ChunkTime.Nanoseconds() / 1000
fmt.Println(chunkTimeInterval, partitionsOption)

// obselete and also not useful in standalone tests
_ = partitionsOption

// TODO: update create hyper table command
var fullCmd = fmt.Sprintf("SELECT %s('%s'::regclass, by_range('time'), create_default_indexes=>FALSE)",
creationCommand, tableName)

fmt.Println("create cmd:", fullCmd)
MustExec(dbBench, fullCmd)

var setChunkCmd = fmt.Sprintf("SELECT set_chunk_time_interval('%s', %d)", tableName, chunkTimeInterval)
fmt.Println("set cmd:", setChunkCmd)
MustExec(dbBench, setChunkCmd)
}
}

Expand Down
Loading