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

Fixed timescaledb loader initialization #255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 8 additions & 11 deletions pkg/targets/timescaledb/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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))
}
}

Expand Down