Merge pull request #1949 from cognitree/cqlgen-1154

cqlgen: added support for static column types #1154
This commit is contained in:
Jonathan Shook 2024-05-17 12:04:49 -05:00 committed by GitHub
commit 54b185afc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 27 additions and 11 deletions

View File

@ -829,7 +829,7 @@ public class CGWorkloadExporter implements BundledApp {
private String genTableColumnDDL(CqlTable cqltable) { private String genTableColumnDDL(CqlTable cqltable) {
return cqltable.getColumnDefs().stream() return cqltable.getColumnDefs().stream()
.map(cd -> cd.getName() + " " + cd.getTrimmedTypedef()) .map(cd -> cd.getName() + " " + cd.getTrimmedTypedef() + (cd.isStatic() ? " STATIC" : ""))
.collect(Collectors.joining(",\n")); .collect(Collectors.joining(",\n"));
} }

View File

@ -430,7 +430,7 @@ columnDefinitionList
// //
columnDefinition columnDefinition
: column dataType primaryKeyColumn? : column dataType (primaryKeyColumn | kwStatic)?
; ;
// //
@ -1013,6 +1013,10 @@ kwFinalfunc
: K_FINALFUNC : K_FINALFUNC
; ;
kwStatic
: K_STATIC
;
kwFrom kwFrom
: K_FROM : K_FROM
; ;

View File

@ -25,10 +25,12 @@ public abstract class CqlColumnBase implements NBNamedElement, NBLabeledElement
private String name; private String name;
private String typedef; private String typedef;
private ColumnPosition position=ColumnPosition.NonKey; private ColumnPosition position=ColumnPosition.NonKey;
private boolean isStatic;
protected CqlColumnBase(String colname, String typedef) { protected CqlColumnBase(String colname, String typedef, boolean isStatic) {
this.typedef = typedef; this.typedef = typedef;
this.name = colname; this.name = colname;
this.isStatic = isStatic;
} }
public void setPosition(ColumnPosition position) { public void setPosition(ColumnPosition position) {
@ -62,7 +64,7 @@ public abstract class CqlColumnBase implements NBNamedElement, NBLabeledElement
@Override @Override
public NBLabels getLabels() { public NBLabels getLabels() {
return NBLabels.forKV("name", name, "type", "column"); return NBLabels.forKV("name", name, "type", "column", "is_static", isStatic);
} }
public boolean isCounter() { public boolean isCounter() {
@ -83,4 +85,11 @@ public abstract class CqlColumnBase implements NBNamedElement, NBLabeledElement
protected abstract String getParentFullName(); protected abstract String getParentFullName();
public boolean isStatic() {
return isStatic;
}
public void setStatic(boolean isStatic) {
this.isStatic = isStatic;
}
} }

View File

@ -235,6 +235,7 @@ public class CqlModelBuilder extends CqlParserBaseListener {
CqlTableColumn coldef = new CqlTableColumn( CqlTableColumn coldef = new CqlTableColumn(
ctx.column().getText(), ctx.column().getText(),
ctx.dataType().getText(), ctx.dataType().getText(),
ctx.kwStatic() != null,
table table
); );
table.addcolumnDef(coldef); table.addcolumnDef(coldef);

View File

@ -22,8 +22,8 @@ public class CqlTableColumn extends CqlColumnBase {
private CqlTable table; private CqlTable table;
public CqlTableColumn(final String colname, final String typedef, final CqlTable table) { public CqlTableColumn(final String colname, final String typedef, final boolean isStatic, final CqlTable table) {
super(colname, typedef); super(colname, typedef, isStatic);
this.table = table; this.table = table;
} }

View File

@ -23,7 +23,7 @@ public class CqlTypeColumn extends CqlColumnBase {
CqlType type; CqlType type;
public CqlTypeColumn(final String colname, final String typedef, final CqlType usertype) { public CqlTypeColumn(final String colname, final String typedef, final CqlType usertype) {
super(colname, typedef); super(colname, typedef, false);
type = usertype; type = usertype;
} }

View File

@ -1,5 +1,6 @@
CREATE TABLE cycling.race_winners ( CREATE TABLE cycling.race_winners (
race_name text, race_name text,
race_position int, race_position int,
cyclist_name FROZEN<fullname>, flag int STATIC,
cyclist_name FROZEN<fullname>,
PRIMARY KEY (race_name, race_position)); PRIMARY KEY (race_name, race_position));

View File

@ -49,7 +49,8 @@ CREATE TABLE baselines.alltypes
a_varint varint, a_varint varint,
an_ascii ascii, an_ascii ascii,
an_inet inet, an_inet inet,
an_int int an_int int,
a_static_int int STATIC
) WITH additional_write_policy = '99PERCENTILE' ) WITH additional_write_policy = '99PERCENTILE'
AND bloom_filter_fp_chance = 0.01 AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}