From be0246b453a096e4a33ba4c919eb8da779030d85 Mon Sep 17 00:00:00 2001 From: semabtariq1 <36853920+semabtariq1@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:21:30 +0500 Subject: [PATCH] Quick fix removing multi node support that might not be the best solution but i just wanted this to work now Signed-off-by: semabtariq1 <36853920+semabtariq1@users.noreply.github.com> --- pkg/targets/timescaledb/creator.go | 50 ++++++++++++------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/pkg/targets/timescaledb/creator.go b/pkg/targets/timescaledb/creator.go index ca36181af..81263164a 100644 --- a/pkg/targets/timescaledb/creator.go +++ b/pkg/targets/timescaledb/creator.go @@ -195,36 +195,26 @@ 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") - - // 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. - // - // If replication factor is greater >= 1, we assume there are at least multiple - // data nodes. We currently use `create_hypertable` for both statements, the - // default behavior is to create a distributed hypertable if `replication_factor` - // is >= 1 - - // 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 { - // 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) - } - - 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 creationCommand string = "create_hypertable" + var partitionsOption string = "" + MustExec(dbBench, "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE") + // Handle partitioning options if NumberPartitions is set + if d.opts.NumberPartitions > 0 { + partitionsOption = fmt.Sprintf("partitioning_column => '%s'::name, number_partitions => %v::smallint", partitionColumn, d.opts.NumberPartitions) + } + + // Construct the query dynamically based on the options + query := fmt.Sprintf("SELECT %s('%s'::regclass, 'time'::name", creationCommand, tableName) + + // Add partitionsOption if specified + if partitionsOption != "" { + query += fmt.Sprintf(", %s", partitionsOption) + } + + // Add chunk_time_interval and create_default_indexes + query += fmt.Sprintf(", chunk_time_interval => %d, create_default_indexes=>FALSE)", d.opts.ChunkTime.Nanoseconds()/1000) + MustExec(dbBench, query) + } } func (d *dbCreator) getCreateIndexOnFieldCmds(hypertable, field, idxType string) []string {