diff --git a/pkg/targets/timescaledb/creator.go b/pkg/targets/timescaledb/creator.go index ca36181af..5ed50c2b5 100644 --- a/pkg/targets/timescaledb/creator.go +++ b/pkg/targets/timescaledb/creator.go @@ -195,11 +195,12 @@ func (d *dbCreator) createTableAndIndexes(dbBench *sql.DB, tableName string, fie } if d.opts.UseHypertable { - var creationCommand string = "create_hypertable" - var partitionsOption string = "replication_factor => NULL" - MustExec(dbBench, "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE") + var options string = fmt.Sprintf( + "chunk_time_interval => %d, create_default_indexes => FALSE", + d.opts.ChunkTime.Nanoseconds()/1000) + // Replication factor determines whether we create a distributed hypertable // or not. If it is unset or zero, then we will create a regular // hypertable with no partitions. @@ -212,18 +213,14 @@ func (d *dbCreator) createTableAndIndexes(dbBench *sql.DB, tableName string, fie // We assume a single partition hypertable. This provides an option to test // partitioning on regular hypertables if d.opts.NumberPartitions > 0 { - partitionsOption = fmt.Sprintf("partitioning_column => '%s'::name, number_partitions => %v::smallint", partitionColumn, d.opts.NumberPartitions) - } - - if d.opts.ReplicationFactor > 0 { + options = fmt.Sprintf("partitioning_column => '%s'::name, number_partitions => %v::smallint, %s", partitionColumn, d.opts.NumberPartitions, options) + } else if d.opts.ReplicationFactor > 0 { // This gives us a future option of testing the impact of // multi-node replication across data nodes - partitionsOption = fmt.Sprintf("partitioning_column => '%s'::name, replication_factor => %v::smallint", partitionColumn, d.opts.ReplicationFactor) + options = fmt.Sprintf("partitioning_column => '%s'::name, replication_factor => %v::smallint, %s", partitionColumn, d.opts.ReplicationFactor, options) } - 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)) + MustExec(dbBench, fmt.Sprintf("SELECT create_hypertable('%s'::regclass, 'time'::name, %s)", tableName, options)) } }