From e2fdbd756a7db7e94da4d6ba61a6d2854860caa3 Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Wed, 17 Jul 2024 10:28:56 +0530 Subject: [PATCH 1/2] Add conf option to disable/enable 'if not exists' for DDL statements. Closes #817 --- .../nosqlbench/cqlgen/core/CGWorkloadExporter.java | 13 ++++++++++--- .../src/main/resources/cqlgen/cqlgen.conf | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/nb-adapters/adapter-cqld4/src/main/java/io/nosqlbench/cqlgen/core/CGWorkloadExporter.java b/nb-adapters/adapter-cqld4/src/main/java/io/nosqlbench/cqlgen/core/CGWorkloadExporter.java index 0a4ec8cde..4678917db 100644 --- a/nb-adapters/adapter-cqld4/src/main/java/io/nosqlbench/cqlgen/core/CGWorkloadExporter.java +++ b/nb-adapters/adapter-cqld4/src/main/java/io/nosqlbench/cqlgen/core/CGWorkloadExporter.java @@ -72,6 +72,7 @@ public class CGWorkloadExporter implements BundledApp { private String namingTemplate; private double partitionMultiplier; private int quantizerDigits; + private boolean disableIfNotExists = false; private Map> blockplan = Map.of(); private final Map timeouts = new HashMap(Map.of( @@ -163,6 +164,9 @@ public class CGWorkloadExporter implements BundledApp { configureTimeouts(cfgmap.get("timeouts")); configureBlocks(cfgmap.get("blockplan")); configureQuantizerDigits(cfgmap.get("quantizer_digits")); + if (cfgmap.get("disable_if_not_exists").equals(true)) { + disableIfNotExists = true; + } this.model = CqlModelParser.parse(ddl, srcpath); List errorlist = model.getReferenceErrors(); @@ -736,9 +740,10 @@ public class CGWorkloadExporter implements BundledApp { private String genKeyspaceDDL(CqlKeyspaceDef keyspace) { return """ - create keyspace KEYSPACE + create keyspace IF_NOT_EXISTS KEYSPACE with replication = {REPLICATION}DURABLEWRITES?; """ + .replace("IF_NOT_EXISTS", disableIfNotExists ? "" : "if not exists") .replace("KEYSPACE", keyspace.getName()) .replace("REPLICATION", keyspace.getReplicationData()) .replace("DURABLEWRITES?", keyspace.isDurableWrites() ? "" : "\n and durable writes = false") @@ -766,10 +771,11 @@ public class CGWorkloadExporter implements BundledApp { private String genTypeDDL(CqlType type) { return """ - create type KEYSPACE.TYPENAME ( + create type IF_NOT_EXISTS KEYSPACE.TYPENAME ( TYPEDEF ); """ + .replace("IF_NOT_EXISTS", disableIfNotExists ? "" : "if not exists") .replace("KEYSPACE", type.getKeyspace().getName()) .replace("TYPENAME", type.getName()) .replace("TYPEDEF", type.getColumnDefs().stream() @@ -782,11 +788,12 @@ public class CGWorkloadExporter implements BundledApp { } return """ - create table if not exists KEYSPACE.TABLE ( + create table IF_NOT_EXISTS KEYSPACE.TABLE ( COLUMN_DEFS, primary key (PRIMARYKEY) )CLUSTERING; """ + .replace("IF_NOT_EXISTS", disableIfNotExists ? "" : "if not exists") .replace("KEYSPACE", cqltable.getKeyspace().getName()) .replace("TABLE", cqltable.getName()) .replace("COLUMN_DEFS", genTableColumnDDL(cqltable)) diff --git a/nb-adapters/adapter-cqld4/src/main/resources/cqlgen/cqlgen.conf b/nb-adapters/adapter-cqld4/src/main/resources/cqlgen/cqlgen.conf index 0aab9c35c..0a8453e35 100644 --- a/nb-adapters/adapter-cqld4/src/main/resources/cqlgen/cqlgen.conf +++ b/nb-adapters/adapter-cqld4/src/main/resources/cqlgen/cqlgen.conf @@ -145,6 +145,6 @@ blockplan: # not needed when tags=block:'main.*' # main: insert, select, scan-10, update - - +# Configuration option for removing 'IF NOT EXISTS' in all generated DDL statements +disable_if_not_exists: false From 310de7eee708102ad9586d2b318b2e2ef50f0d88 Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Thu, 18 Jul 2024 12:22:50 +0530 Subject: [PATCH 2/2] rename conf disable_if_not_exists to enable_if_exists --- .../cqlgen/core/CGWorkloadExporter.java | 18 +++++++++--------- .../src/main/resources/cqlgen/cqlgen.conf | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nb-adapters/adapter-cqld4/src/main/java/io/nosqlbench/cqlgen/core/CGWorkloadExporter.java b/nb-adapters/adapter-cqld4/src/main/java/io/nosqlbench/cqlgen/core/CGWorkloadExporter.java index 4678917db..4f7efcea8 100644 --- a/nb-adapters/adapter-cqld4/src/main/java/io/nosqlbench/cqlgen/core/CGWorkloadExporter.java +++ b/nb-adapters/adapter-cqld4/src/main/java/io/nosqlbench/cqlgen/core/CGWorkloadExporter.java @@ -72,7 +72,7 @@ public class CGWorkloadExporter implements BundledApp { private String namingTemplate; private double partitionMultiplier; private int quantizerDigits; - private boolean disableIfNotExists = false; + private boolean enableIfExists = true; private Map> blockplan = Map.of(); private final Map timeouts = new HashMap(Map.of( @@ -164,8 +164,8 @@ public class CGWorkloadExporter implements BundledApp { configureTimeouts(cfgmap.get("timeouts")); configureBlocks(cfgmap.get("blockplan")); configureQuantizerDigits(cfgmap.get("quantizer_digits")); - if (cfgmap.get("disable_if_not_exists").equals(true)) { - disableIfNotExists = true; + if (cfgmap.get("enable_if_exists").equals(false)) { + enableIfExists = false; } this.model = CqlModelParser.parse(ddl, srcpath); @@ -643,7 +643,7 @@ public class CGWorkloadExporter implements BundledApp { ops.put( namer.nameFor(table, "optype", "drop", "blockname", blockname), Map.of( - "simple", "drop table if exists " + table.getFullName() + ";", + "simple", (enableIfExists ? "drop table if exists " : "drop table ") + table.getFullName() + ";", "timeout", timeouts.get("drop") ) ); @@ -659,7 +659,7 @@ public class CGWorkloadExporter implements BundledApp { ops.put( namer.nameFor(type, "optype", "drop-type", "blockname", blockname), Map.of( - "simple", "drop type if exists " + type.getKeyspace() + "." + type.getName() + ";", + "simple", (enableIfExists ? "drop type if exists " : "drop type ") + "." + type.getName() + ";", "timeout", timeouts.get("drop") ) ); @@ -675,7 +675,7 @@ public class CGWorkloadExporter implements BundledApp { ops.put( namer.nameFor(type, "optype", "drop-keyspace", "blockname", blockname), Map.of( - "simple", "drop keyspace if exists " + type.getKeyspace() + ";", + "simple", (enableIfExists ? "drop keyspace if exists " : "drop keyspace ") + type.getKeyspace() + ";", "timeout", timeouts.get("drop") ) ); @@ -743,7 +743,7 @@ public class CGWorkloadExporter implements BundledApp { create keyspace IF_NOT_EXISTS KEYSPACE with replication = {REPLICATION}DURABLEWRITES?; """ - .replace("IF_NOT_EXISTS", disableIfNotExists ? "" : "if not exists") + .replace("IF_NOT_EXISTS", enableIfExists ? "if not exists" : "") .replace("KEYSPACE", keyspace.getName()) .replace("REPLICATION", keyspace.getReplicationData()) .replace("DURABLEWRITES?", keyspace.isDurableWrites() ? "" : "\n and durable writes = false") @@ -775,7 +775,7 @@ public class CGWorkloadExporter implements BundledApp { TYPEDEF ); """ - .replace("IF_NOT_EXISTS", disableIfNotExists ? "" : "if not exists") + .replace("IF_NOT_EXISTS", enableIfExists ? "if not exists" : "") .replace("KEYSPACE", type.getKeyspace().getName()) .replace("TYPENAME", type.getName()) .replace("TYPEDEF", type.getColumnDefs().stream() @@ -793,7 +793,7 @@ public class CGWorkloadExporter implements BundledApp { primary key (PRIMARYKEY) )CLUSTERING; """ - .replace("IF_NOT_EXISTS", disableIfNotExists ? "" : "if not exists") + .replace("IF_NOT_EXISTS", enableIfExists ? "if not exists" : "") .replace("KEYSPACE", cqltable.getKeyspace().getName()) .replace("TABLE", cqltable.getName()) .replace("COLUMN_DEFS", genTableColumnDDL(cqltable)) diff --git a/nb-adapters/adapter-cqld4/src/main/resources/cqlgen/cqlgen.conf b/nb-adapters/adapter-cqld4/src/main/resources/cqlgen/cqlgen.conf index 0a8453e35..494fb4424 100644 --- a/nb-adapters/adapter-cqld4/src/main/resources/cqlgen/cqlgen.conf +++ b/nb-adapters/adapter-cqld4/src/main/resources/cqlgen/cqlgen.conf @@ -145,6 +145,6 @@ blockplan: # not needed when tags=block:'main.*' # main: insert, select, scan-10, update -# Configuration option for removing 'IF NOT EXISTS' in all generated DDL statements -disable_if_not_exists: false +# Configuration option for adding 'IF NOT EXISTS' or 'IF EXISTS' in all generated DDL statements +enable_if_exists: true