mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
checkpoint
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lang.cqlast;
|
||||
|
||||
import io.nosqlbench.virtdata.lang.generated.CqlParser;
|
||||
import io.nosqlbench.virtdata.lang.generated.CqlParserBaseListener;
|
||||
|
||||
public class CqlAstBuilder extends CqlParserBaseListener {
|
||||
|
||||
CqlKeyspace keyspace = new CqlKeyspace();
|
||||
|
||||
@Override
|
||||
public void enterCreateTable(CqlParser.CreateTableContext ctx) {
|
||||
keyspace.addTable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitCreateTable(CqlParser.CreateTableContext ctx) {
|
||||
keyspace.setTableName(ctx.table().OBJECT_NAME().getSymbol().getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterColumnDefinition(CqlParser.ColumnDefinitionContext ctx) {
|
||||
System.out.println("here");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitColumnDefinition(CqlParser.ColumnDefinitionContext ctx) {
|
||||
System.out.println("here");
|
||||
keyspace.addTableColumn(
|
||||
ctx.dataType().dataTypeName().getText(),
|
||||
ctx.column().OBJECT_NAME().getSymbol().getText()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CqlAstBuilder{" +
|
||||
"keyspace=" + keyspace +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lang.cqlast;
|
||||
|
||||
public class CqlField {
|
||||
String name;
|
||||
String type;
|
||||
|
||||
public CqlField(String type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CqlField{" +
|
||||
"name='" + name + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lang.cqlast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CqlKeyspace {
|
||||
List<CqlTable> tables = new ArrayList<>();
|
||||
CqlTable lastAddedTable = null;
|
||||
|
||||
public void addTable() {
|
||||
lastAddedTable = new CqlTable();
|
||||
tables.add(lastAddedTable);
|
||||
}
|
||||
|
||||
public void addColumnDef(String type, String name) {
|
||||
lastAddedTable.addcolumnDef(new CqlField(type, name));
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
lastAddedTable.setName(tableName);
|
||||
}
|
||||
|
||||
public void addTableColumn(String type, String fieldName) {
|
||||
lastAddedTable.addcolumnDef(type,fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CqlKeyspace{" +
|
||||
"tables=" + tables +
|
||||
", lastAddedTable=" + lastAddedTable +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lang.cqlast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CqlTable {
|
||||
String name = "";
|
||||
List<CqlField> fields = new ArrayList();
|
||||
|
||||
public CqlTable() {
|
||||
}
|
||||
|
||||
public CqlTable(String tableName) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addcolumnDef(CqlField cqlField) {
|
||||
this.fields.add(cqlField);
|
||||
}
|
||||
|
||||
public void setName(String tableName) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addcolumnDef(String type, String fieldName) {
|
||||
fields.add(new CqlField(type, fieldName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CqlTable{" +
|
||||
"name='" + name + '\'' +
|
||||
", fields=" + fields +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
lexer grammar CqlLexer;
|
||||
|
||||
options {
|
||||
caseInsensitive = true;
|
||||
}
|
||||
|
||||
// Operators and Punctuators
|
||||
|
||||
LR_BRACKET: '(';
|
||||
RR_BRACKET: ')';
|
||||
LC_BRACKET: '{';
|
||||
RC_BRACKET: '}';
|
||||
LS_BRACKET: '[';
|
||||
RS_BRACKET: ']';
|
||||
COMMA: ',';
|
||||
SEMI: ';';
|
||||
COLON: ':';
|
||||
DOT: '.';
|
||||
STAR: '*';
|
||||
DIVIDE: '/';
|
||||
MODULE: '%';
|
||||
PLUS: '+';
|
||||
MINUSMINUS: '--';
|
||||
MINUS: '-';
|
||||
DQUOTE: '"';
|
||||
SQUOTE: '\'';
|
||||
OPERATOR_EQ: '=';
|
||||
OPERATOR_LT: '<';
|
||||
OPERATOR_GT: '>';
|
||||
OPERATOR_LTE: '<=';
|
||||
OPERATOR_GTE: '>=';
|
||||
|
||||
// Keywords
|
||||
|
||||
K_ADD: 'ADD';
|
||||
K_AGGREGATE: 'AGGREGATE';
|
||||
K_ALL: 'ALL';
|
||||
K_ALLOW: 'ALLOW';
|
||||
K_ALTER: 'ALTER';
|
||||
K_AND: 'AND';
|
||||
K_ANY: 'ANY';
|
||||
K_APPLY: 'APPLY';
|
||||
K_AS: 'AS';
|
||||
K_ASC: 'ASC';
|
||||
K_AUTHORIZE: 'AUTHORIZE';
|
||||
K_BATCH: 'BATCH';
|
||||
K_BEGIN: 'BEGIN';
|
||||
K_BY: 'BY';
|
||||
K_CALLED: 'CALLED';
|
||||
K_CLUSTERING: 'CLUSTERING';
|
||||
K_COLUMNFAMILY: 'COLUMNFAMILY';
|
||||
K_COMPACT: 'COMPACT';
|
||||
K_CONSISTENCY: 'CONSISTENCY';
|
||||
K_CONTAINS: 'CONTAINS';
|
||||
K_CREATE: 'CREATE';
|
||||
K_CUSTOM: 'CUSTOM';
|
||||
K_DELETE: 'DELETE';
|
||||
K_DESC: 'DESC';
|
||||
K_DESCRIBE: 'DESCRIBE';
|
||||
K_DISTINCT: 'DISTINCT';
|
||||
K_DROP: 'DROP';
|
||||
K_DURABLE_WRITES: 'DURABLE_WRITES';
|
||||
K_EACH_QUORUM: 'EACH_QUORUM';
|
||||
K_ENTRIES: 'ENTRIES';
|
||||
K_EXECUTE: 'EXECUTE';
|
||||
K_EXISTS: 'EXISTS';
|
||||
K_FALSE: 'FALSE';
|
||||
K_FILTERING: 'FILTERING';
|
||||
K_FINALFUNC: 'FINALFUNC';
|
||||
K_FROM: 'FROM';
|
||||
K_FULL: 'FULL';
|
||||
K_FUNCTION: 'FUNCTION';
|
||||
K_FUNCTIONS: 'FUNCTIONS';
|
||||
K_GRANT: 'GRANT';
|
||||
K_IF: 'IF';
|
||||
K_IN: 'IN';
|
||||
K_INDEX: 'INDEX';
|
||||
K_INFINITY: 'INFINITY';
|
||||
K_INITCOND: 'INITCOND';
|
||||
K_INPUT: 'INPUT';
|
||||
K_INSERT: 'INSERT';
|
||||
K_INTO: 'INTO';
|
||||
K_IS: 'IS';
|
||||
K_JSON: 'JSON';
|
||||
K_KEY: 'KEY';
|
||||
K_KEYS: 'KEYS';
|
||||
K_KEYSPACE: 'KEYSPACE';
|
||||
K_KEYSPACES: 'KEYSPACES';
|
||||
K_LANGUAGE: 'LANGUAGE';
|
||||
K_LEVEL: 'LEVEL';
|
||||
K_LIMIT: 'LIMIT';
|
||||
K_LOCAL_ONE: 'LOCAL_ONE';
|
||||
K_LOCAL_QUORUM: 'LOCAL_QUORUM';
|
||||
K_LOGGED: 'LOGGED';
|
||||
K_LOGIN: 'LOGIN';
|
||||
K_MATERIALIZED: 'MATERIALIZED';
|
||||
K_MODIFY: 'MODIFY';
|
||||
K_NAN: 'NAN';
|
||||
K_NORECURSIVE: 'NORECURSIVE';
|
||||
K_NOSUPERUSER: 'NOSUPERUSER';
|
||||
K_NOT: 'NOT';
|
||||
K_NULL: 'NULL';
|
||||
K_OF: 'OF';
|
||||
K_ON: 'ON';
|
||||
K_ONE: 'ONE';
|
||||
K_OPTIONS: 'OPTIONS';
|
||||
K_OR: 'OR';
|
||||
K_ORDER: 'ORDER';
|
||||
K_PARTITION: 'PARTITION';
|
||||
K_PASSWORD: 'PASSWORD';
|
||||
K_PER: 'PER';
|
||||
K_PERMISSION: 'PERMISSION';
|
||||
K_PERMISSIONS: 'PERMISSIONS';
|
||||
K_PRIMARY: 'PRIMARY';
|
||||
K_QUORUM: 'QUORUM';
|
||||
K_RENAME: 'RENAME';
|
||||
K_REPLACE: 'REPLACE';
|
||||
K_REPLICATION: 'REPLICATION';
|
||||
K_RETURNS: 'RETURNS';
|
||||
K_REVOKE: 'REVOKE';
|
||||
K_ROLE: 'ROLE';
|
||||
K_ROLES: 'ROLES';
|
||||
K_SCHEMA: 'SCHEMA';
|
||||
K_SELECT: 'SELECT';
|
||||
K_SET: 'SET';
|
||||
K_SFUNC: 'SFUNC';
|
||||
K_STATIC: 'STATIC';
|
||||
K_STORAGE: 'STORAGE';
|
||||
K_STYPE: 'STYPE';
|
||||
K_SUPERUSER: 'SUPERUSER';
|
||||
K_TABLE: 'TABLE';
|
||||
K_THREE: 'THREE';
|
||||
K_TIMESTAMP: 'TIMESTAMP';
|
||||
K_TO: 'TO';
|
||||
K_TOKEN: 'TOKEN';
|
||||
K_TRIGGER: 'TRIGGER';
|
||||
K_TRUE: 'TRUE';
|
||||
K_TRUNCATE: 'TRUNCATE';
|
||||
K_TTL: 'TTL';
|
||||
K_TWO: 'TWO';
|
||||
K_TYPE: 'TYPE';
|
||||
K_UNLOGGED: 'UNLOGGED';
|
||||
K_UPDATE: 'UPDATE';
|
||||
K_USE: 'USE';
|
||||
K_USER: 'USER';
|
||||
K_USING: 'USING';
|
||||
K_UUID: 'UUID';
|
||||
K_VALUES: 'VALUES';
|
||||
K_VIEW: 'VIEW';
|
||||
K_WHERE: 'WHERE';
|
||||
K_WITH: 'WITH';
|
||||
K_WRITETIME: 'WRITETIME';
|
||||
K_ASCII: 'ASCII';
|
||||
K_BIGINT: 'BIGINT';
|
||||
K_BLOB: 'BLOB';
|
||||
K_BOOLEAN: 'BOOLEAN';
|
||||
K_COUNTER: 'COUNTER';
|
||||
K_DATE: 'DATE';
|
||||
K_DECIMAL: 'DECIMAL';
|
||||
K_DOUBLE: 'DOUBLE';
|
||||
K_FLOAT: 'FLOAT';
|
||||
K_FROZEN: 'FROZEN';
|
||||
K_INET: 'INET';
|
||||
K_INT: 'INT';
|
||||
K_LIST: 'LIST';
|
||||
K_MAP: 'MAP';
|
||||
K_SMALLINT: 'SMALLINT';
|
||||
K_TEXT: 'TEXT';
|
||||
K_TIMEUUID: 'TIMEUUID';
|
||||
K_TIME: 'TIME';
|
||||
K_TINYINT: 'TINYINT';
|
||||
K_TUPLE: 'TUPLE';
|
||||
K_VARCHAR: 'VARCHAR';
|
||||
K_VARINT: 'VARINT';
|
||||
|
||||
// Literals
|
||||
|
||||
CODE_BLOCK: '$$' (~ '$' | '$' ~'$')* '$$';
|
||||
|
||||
STRING_LITERAL: '\'' ('\\' . | '\'\'' | ~('\'' | '\\'))* '\'';
|
||||
|
||||
DECIMAL_LITERAL: DEC_DIGIT+;
|
||||
|
||||
FLOAT_LITERAL: MINUS? [0-9]+ (DOT [0-9]+)?;
|
||||
|
||||
HEXADECIMAL_LITERAL
|
||||
: 'X' '\'' (HEX_DIGIT HEX_DIGIT)+ '\''
|
||||
| '0X' HEX_DIGIT+
|
||||
;
|
||||
|
||||
REAL_LITERAL
|
||||
: DEC_DIGIT+ '.'? EXPONENT_NUM_PART
|
||||
| DEC_DIGIT* '.' DEC_DIGIT+ EXPONENT_NUM_PART?
|
||||
;
|
||||
|
||||
OBJECT_NAME
|
||||
: [A-Z] [A-Z0-9_$]*
|
||||
| '"' ~'"'+ '"'
|
||||
;
|
||||
|
||||
UUID: HEX_4DIGIT HEX_4DIGIT '-' HEX_4DIGIT '-' HEX_4DIGIT '-' HEX_4DIGIT '-' HEX_4DIGIT HEX_4DIGIT HEX_4DIGIT;
|
||||
|
||||
// Hidden
|
||||
|
||||
SPACE: [ \t\r\n]+ -> channel (HIDDEN);
|
||||
SPEC_MYSQL_COMMENT: '/*!' .+? '*/' -> channel (HIDDEN);
|
||||
COMMENT_INPUT: '/*' .*? '*/' -> channel (HIDDEN);
|
||||
LINE_COMMENT: (
|
||||
('-- ' | '#' | '//') ~ [\r\n]* ('\r'? '\n' | EOF)
|
||||
| '--' ('\r'? '\n' | EOF)
|
||||
) -> channel (HIDDEN);
|
||||
|
||||
// Fragments
|
||||
|
||||
fragment HEX_4DIGIT: [0-9A-F] [0-9A-F] [0-9A-F] [0-9A-F];
|
||||
|
||||
fragment HEX_DIGIT: [0-9A-F];
|
||||
|
||||
fragment DEC_DIGIT: [0-9];
|
||||
|
||||
fragment EXPONENT_NUM_PART: 'E' '-'? DEC_DIGIT+;
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lang.parser;
|
||||
|
||||
import io.nosqlbench.virtdata.lang.cqlast.CqlAstBuilder;
|
||||
import io.nosqlbench.virtdata.lang.generated.CqlLexer;
|
||||
import io.nosqlbench.virtdata.lang.generated.CqlParser;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CodePointCharStream;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
public class CqlParserHarness {
|
||||
private final static Logger logger = LogManager.getLogger(CqlParserHarness.class);
|
||||
|
||||
public void parse(String input) {
|
||||
|
||||
try {
|
||||
CodePointCharStream cstream = CharStreams.fromString(input);
|
||||
|
||||
CqlLexer lexer = new CqlLexer(cstream);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
CqlParser parser = new CqlParser(tokens);
|
||||
|
||||
|
||||
CqlAstBuilder astListener = new CqlAstBuilder();
|
||||
parser.addParseListener(astListener);
|
||||
|
||||
CqlParser.RootContext keyspaceParser = parser.root();
|
||||
String tree = keyspaceParser.toStringTree();
|
||||
|
||||
// System.out.println("parsetree:\n" + tree);
|
||||
System.out.println(astListener.toString());
|
||||
|
||||
|
||||
|
||||
|
||||
// VirtDataParser.VirtdataFlowContext virtdataFlowContext = parser.virtdataFlow();
|
||||
// logger.trace("parse tree: " + virtdataFlowContext.toStringTree(parser));
|
||||
|
||||
// if (astListener.hasErrors()) {
|
||||
// System.out.println(astListener.getErrorNodes());
|
||||
// }
|
||||
|
||||
// VirtDataAST ast = astListener.getModel();
|
||||
// List<VirtDataFlow> flows = ast.getFlows();
|
||||
// if (flows.size() > 1) {
|
||||
// throw new RuntimeException("Only one flow expected here.");
|
||||
// }
|
||||
//
|
||||
// if (astListener.hasErrors()) {
|
||||
// throw new RuntimeException("Error parsing input '" + input + "'");
|
||||
// }
|
||||
//
|
||||
// return new ParseResult(flows.get(0));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error while parsing flow:" + e.getMessage());
|
||||
throw e;
|
||||
// return new ParseResult(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lang.parser;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CqlParserHarnessTest {
|
||||
|
||||
@Test
|
||||
public void testCqlParserHarness() {
|
||||
CqlParserHarness harness = new CqlParserHarness();
|
||||
harness.parse("""
|
||||
|
||||
CREATE KEYSPACE cycling
|
||||
WITH REPLICATION = {\s
|
||||
'class' : 'SimpleStrategy',\s
|
||||
'replication_factor' : 1\s
|
||||
};
|
||||
|
||||
CREATE TABLE cycling.race_winners (
|
||||
race_name text,\s
|
||||
race_position int,\s
|
||||
cyclist_name FROZEN<fullname>,\s
|
||||
PRIMARY KEY (race_name, race_position));
|
||||
""");
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user