checkpoint

This commit is contained in:
Jonathan Shook 2022-07-07 11:20:12 -07:00
parent 1ea3391e76
commit ce070d2c19
9 changed files with 73 additions and 20 deletions

View File

@ -91,4 +91,31 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.10.1</version>
<configuration>
<sourceDirectory>src/main/java/io/nosqlbench/converters/cql/cql/grammars</sourceDirectory>
<arguments>
<argument>-package</argument>
<argument>io.nosqlbench.converters.cql.generated</argument>
</arguments>
<outputDirectory>src/main/java/io/nosqlbench/converters/cql/generated</outputDirectory>
</configuration>
<executions>
<execution>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -14,23 +14,38 @@
* limitations under the License.
*/
package io.nosqlbench.virtdata.lang.cqlast;
package io.nosqlbench.converters.cql.cql.cqlast;
import io.nosqlbench.virtdata.lang.generated.CqlParser;
import io.nosqlbench.virtdata.lang.generated.CqlParserBaseListener;
import io.nosqlbench.converters.cql.generated.CqlParser;
import io.nosqlbench.converters.cql.generated.CqlParserBaseListener;
import java.util.ArrayList;
import java.util.List;
public class CqlAstBuilder extends CqlParserBaseListener {
CqlKeyspace keyspace = new CqlKeyspace();
List<CqlKeyspace> keyspaces = new ArrayList<>():
CqlKeyspace lastKeyspace = null;
@Override
public void enterKeyspace(CqlParser.KeyspaceContext ctx) {
lastKeyspace = new CqlKeyspace();
this.keyspaces.add(lastKeyspace);
}
@Override
public void exitKeyspace(CqlParser.KeyspaceContext ctx) {
lastKeyspace.setKeyspaceName(ctx.OBJECT_NAME().getSymbol().getText());
}
@Override
public void enterCreateTable(CqlParser.CreateTableContext ctx) {
keyspace.addTable();
lastKeyspace.addTable();
}
@Override
public void exitCreateTable(CqlParser.CreateTableContext ctx) {
keyspace.setTableName(ctx.table().OBJECT_NAME().getSymbol().getText());
lastKeyspace.setTableName(ctx.table().OBJECT_NAME().getSymbol().getText());
}
@Override
@ -41,7 +56,7 @@ public class CqlAstBuilder extends CqlParserBaseListener {
@Override
public void exitColumnDefinition(CqlParser.ColumnDefinitionContext ctx) {
System.out.println("here");
keyspace.addTableColumn(
lastKeyspace.addTableColumn(
ctx.dataType().dataTypeName().getText(),
ctx.column().OBJECT_NAME().getSymbol().getText()
);
@ -50,7 +65,8 @@ public class CqlAstBuilder extends CqlParserBaseListener {
@Override
public String toString() {
return "CqlAstBuilder{" +
"keyspace=" + keyspace +
"keyspaces=" + keyspaces +
", lastKeyspace=" + lastKeyspace +
'}';
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.nosqlbench.virtdata.lang.cqlast;
package io.nosqlbench.converters.cql.cql.cqlast;
public class CqlField {
String name;

View File

@ -14,15 +14,24 @@
* limitations under the License.
*/
package io.nosqlbench.virtdata.lang.cqlast;
package io.nosqlbench.converters.cql.cql.cqlast;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class CqlKeyspace {
String keyspaceName= "";
List<CqlTable> tables = new ArrayList<>();
CqlTable lastAddedTable = null;
public CqlKeyspace() {
}
public void setKeyspaceName(String name) {
this.keyspaceName=name;
}
public void addTable() {
lastAddedTable = new CqlTable();
tables.add(lastAddedTable);
@ -42,9 +51,10 @@ public class CqlKeyspace {
@Override
public String toString() {
return "CqlKeyspace{" +
"tables=" + tables +
", lastAddedTable=" + lastAddedTable +
'}';
return "keyspace:" + keyspaceName+"\n"+
" tables:\n"+
(tables.stream().map(Object::toString)
.map(s -> " "+s)
.collect(Collectors.joining("\n")));
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.nosqlbench.virtdata.lang.cqlast;
package io.nosqlbench.converters.cql.cql.cqlast;
import java.util.ArrayList;
import java.util.List;

View File

@ -14,11 +14,11 @@
* limitations under the License.
*/
package io.nosqlbench.virtdata.lang.parser;
package io.nosqlbench.converters.cql.cql.parser;
import io.nosqlbench.virtdata.lang.cqlast.CqlAstBuilder;
import io.nosqlbench.virtdata.lang.generated.CqlLexer;
import io.nosqlbench.virtdata.lang.generated.CqlParser;
import io.nosqlbench.converters.cql.cql.cqlast.CqlAstBuilder;
import io.nosqlbench.converters.cql.generated.CqlLexer;
import io.nosqlbench.converters.cql.generated.CqlParser;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CodePointCharStream;
import org.antlr.v4.runtime.CommonTokenStream;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.nosqlbench.virtdata.lang.parser;
package io.nosqlbench.converters.cql.cql.parser;
import org.junit.jupiter.api.Test;