mirror of https://github.com/apache/cassandra
CASSANDRA-296 remove CQL
git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@802911 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
38c2556834
commit
8455ebfe87
22
build.xml
22
build.xml
|
|
@ -94,26 +94,6 @@
|
|||
</java>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
This generates the CQL grammar files from Cql.g
|
||||
-->
|
||||
<target name="check-gen-cql-grammar">
|
||||
<uptodate property="cqlUpToDate"
|
||||
srcfile="${build.src}/org/apache/cassandra/cql/compiler/parse/Cql.g"
|
||||
targetfile="${build.src.gen-java}/org/apache/cassandra/cql/compiler/parse/Cql.tokens"/>
|
||||
</target>
|
||||
|
||||
<target name="gen-cql-grammar" depends="check-gen-cql-grammar" unless="cqlUpToDate">
|
||||
<echo>Building Grammar ${build.src}/org/apache/cassandra/cql/compiler/parse/Cql.g ....</echo>
|
||||
<java classname="org.antlr.Tool"
|
||||
classpath="${build.lib}/antlr-3.1.3.jar"
|
||||
fork="true">
|
||||
<arg value="${build.src}/org/apache/cassandra/cql/compiler/parse/Cql.g" />
|
||||
<arg value="-fo" />
|
||||
<arg value="${build.src.gen-java}/org/apache/cassandra/cql/compiler/parse/" />
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="gen-thrift-java">
|
||||
<echo>Generating Thrift Java code from ${basedir}/interface/cassandra.thrift ....</echo>
|
||||
<exec executable="thrift" dir="${basedir}/interface">
|
||||
|
|
@ -134,7 +114,7 @@
|
|||
<target name="build-subprojects"/>
|
||||
<target name="codecoverage" depends="cobertura-instrument,test,cobertura-report"/>
|
||||
|
||||
<target depends="init,gen-cli-grammar,gen-cql-grammar" name="build-project">
|
||||
<target depends="init,gen-cli-grammar" name="build-project">
|
||||
<echo message="${ant.project.name}: ${ant.file}"/>
|
||||
<javac debug="true" debuglevel="${debuglevel}" destdir="${build.classes}">
|
||||
<src path="${build.src}"/>
|
||||
|
|
|
|||
|
|
@ -169,8 +169,5 @@ service Cassandra {
|
|||
// describe specified keyspace
|
||||
map<string, map<string, string>> describe_keyspace(1:string keyspace)
|
||||
throws (1: NotFoundException nfe),
|
||||
|
||||
// execute a CQL query
|
||||
CqlResult execute_query(1:string query)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,8 +76,9 @@ public class BatchMutation implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
public BatchMutation setKey(String key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetKey() {
|
||||
|
|
@ -95,23 +96,13 @@ public class BatchMutation implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
}
|
||||
|
||||
public int getCfmapSize() {
|
||||
return (this.cfmap == null) ? 0 : this.cfmap.size();
|
||||
}
|
||||
|
||||
public void putToCfmap(String key, List<Column> val) {
|
||||
if (this.cfmap == null) {
|
||||
this.cfmap = new HashMap<String,List<Column>>();
|
||||
}
|
||||
this.cfmap.put(key, val);
|
||||
}
|
||||
|
||||
public Map<String,List<Column>> getCfmap() {
|
||||
return this.cfmap;
|
||||
}
|
||||
|
||||
public void setCfmap(Map<String,List<Column>> cfmap) {
|
||||
public BatchMutation setCfmap(Map<String,List<Column>> cfmap) {
|
||||
this.cfmap = cfmap;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetCfmap() {
|
||||
|
|
|
|||
|
|
@ -76,8 +76,9 @@ public class BatchMutationSuper implements TBase, java.io.Serializable, Cloneabl
|
|||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
public BatchMutationSuper setKey(String key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetKey() {
|
||||
|
|
@ -95,23 +96,13 @@ public class BatchMutationSuper implements TBase, java.io.Serializable, Cloneabl
|
|||
}
|
||||
}
|
||||
|
||||
public int getCfmapSize() {
|
||||
return (this.cfmap == null) ? 0 : this.cfmap.size();
|
||||
}
|
||||
|
||||
public void putToCfmap(String key, List<SuperColumn> val) {
|
||||
if (this.cfmap == null) {
|
||||
this.cfmap = new HashMap<String,List<SuperColumn>>();
|
||||
}
|
||||
this.cfmap.put(key, val);
|
||||
}
|
||||
|
||||
public Map<String,List<SuperColumn>> getCfmap() {
|
||||
return this.cfmap;
|
||||
}
|
||||
|
||||
public void setCfmap(Map<String,List<SuperColumn>> cfmap) {
|
||||
public BatchMutationSuper setCfmap(Map<String,List<SuperColumn>> cfmap) {
|
||||
this.cfmap = cfmap;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetCfmap() {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -89,8 +89,9 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(byte[] name) {
|
||||
public Column setName(byte[] name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetName() {
|
||||
|
|
@ -112,8 +113,9 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(byte[] value) {
|
||||
public Column setValue(byte[] value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetValue() {
|
||||
|
|
@ -135,9 +137,10 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
public Column setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
this.__isset.timestamp = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetTimestamp() {
|
||||
|
|
|
|||
|
|
@ -76,8 +76,9 @@ public class ColumnOrSuperColumn implements TBase, java.io.Serializable, Cloneab
|
|||
return this.column;
|
||||
}
|
||||
|
||||
public void setColumn(Column column) {
|
||||
public ColumnOrSuperColumn setColumn(Column column) {
|
||||
this.column = column;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetColumn() {
|
||||
|
|
@ -99,8 +100,9 @@ public class ColumnOrSuperColumn implements TBase, java.io.Serializable, Cloneab
|
|||
return this.super_column;
|
||||
}
|
||||
|
||||
public void setSuper_column(SuperColumn super_column) {
|
||||
public ColumnOrSuperColumn setSuper_column(SuperColumn super_column) {
|
||||
this.super_column = super_column;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetSuper_column() {
|
||||
|
|
@ -250,14 +252,18 @@ public class ColumnOrSuperColumn implements TBase, java.io.Serializable, Cloneab
|
|||
|
||||
oprot.writeStructBegin(STRUCT_DESC);
|
||||
if (this.column != null) {
|
||||
oprot.writeFieldBegin(COLUMN_FIELD_DESC);
|
||||
this.column.write(oprot);
|
||||
oprot.writeFieldEnd();
|
||||
if (isSetColumn()) {
|
||||
oprot.writeFieldBegin(COLUMN_FIELD_DESC);
|
||||
this.column.write(oprot);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
}
|
||||
if (this.super_column != null) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
this.super_column.write(oprot);
|
||||
oprot.writeFieldEnd();
|
||||
if (isSetSuper_column()) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
this.super_column.write(oprot);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
}
|
||||
oprot.writeFieldStop();
|
||||
oprot.writeStructEnd();
|
||||
|
|
|
|||
|
|
@ -77,8 +77,9 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.column_family;
|
||||
}
|
||||
|
||||
public void setColumn_family(String column_family) {
|
||||
public ColumnParent setColumn_family(String column_family) {
|
||||
this.column_family = column_family;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetColumn_family() {
|
||||
|
|
@ -100,8 +101,9 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.super_column;
|
||||
}
|
||||
|
||||
public void setSuper_column(byte[] super_column) {
|
||||
public ColumnParent setSuper_column(byte[] super_column) {
|
||||
this.super_column = super_column;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetSuper_column() {
|
||||
|
|
@ -254,9 +256,11 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
oprot.writeFieldEnd();
|
||||
}
|
||||
if (this.super_column != null) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
oprot.writeBinary(this.super_column);
|
||||
oprot.writeFieldEnd();
|
||||
if (isSetSuper_column()) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
oprot.writeBinary(this.super_column);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
}
|
||||
oprot.writeFieldStop();
|
||||
oprot.writeStructEnd();
|
||||
|
|
|
|||
|
|
@ -88,8 +88,9 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.column_family;
|
||||
}
|
||||
|
||||
public void setColumn_family(String column_family) {
|
||||
public ColumnPath setColumn_family(String column_family) {
|
||||
this.column_family = column_family;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetColumn_family() {
|
||||
|
|
@ -111,8 +112,9 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.super_column;
|
||||
}
|
||||
|
||||
public void setSuper_column(byte[] super_column) {
|
||||
public ColumnPath setSuper_column(byte[] super_column) {
|
||||
this.super_column = super_column;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetSuper_column() {
|
||||
|
|
@ -134,8 +136,9 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.column;
|
||||
}
|
||||
|
||||
public void setColumn(byte[] column) {
|
||||
public ColumnPath setColumn(byte[] column) {
|
||||
this.column = column;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetColumn() {
|
||||
|
|
@ -317,14 +320,18 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
oprot.writeFieldEnd();
|
||||
}
|
||||
if (this.super_column != null) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
oprot.writeBinary(this.super_column);
|
||||
oprot.writeFieldEnd();
|
||||
if (isSetSuper_column()) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
oprot.writeBinary(this.super_column);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
}
|
||||
if (this.column != null) {
|
||||
oprot.writeFieldBegin(COLUMN_FIELD_DESC);
|
||||
oprot.writeBinary(this.column);
|
||||
oprot.writeFieldEnd();
|
||||
if (isSetColumn()) {
|
||||
oprot.writeFieldBegin(COLUMN_FIELD_DESC);
|
||||
oprot.writeBinary(this.column);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
}
|
||||
oprot.writeFieldStop();
|
||||
oprot.writeStructEnd();
|
||||
|
|
|
|||
|
|
@ -19,7 +19,12 @@ public class ConsistencyLevel {
|
|||
public static final int QUORUM = 2;
|
||||
public static final int ALL = 3;
|
||||
|
||||
public static final IntRangeSet VALID_VALUES = new IntRangeSet(ZERO, ONE, QUORUM, ALL);
|
||||
public static final IntRangeSet VALID_VALUES = new IntRangeSet(
|
||||
ZERO,
|
||||
ONE,
|
||||
QUORUM,
|
||||
ALL );
|
||||
|
||||
public static final Map<Integer, String> VALUES_TO_NAMES = new HashMap<Integer, String>() {{
|
||||
put(ZERO, "ZERO");
|
||||
put(ONE, "ONE");
|
||||
|
|
|
|||
|
|
@ -87,9 +87,10 @@ public class CqlResult implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.error_code;
|
||||
}
|
||||
|
||||
public void setError_code(int error_code) {
|
||||
public CqlResult setError_code(int error_code) {
|
||||
this.error_code = error_code;
|
||||
this.__isset.error_code = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetError_code() {
|
||||
|
|
@ -109,8 +110,9 @@ public class CqlResult implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.error_txt;
|
||||
}
|
||||
|
||||
public void setError_txt(String error_txt) {
|
||||
public CqlResult setError_txt(String error_txt) {
|
||||
this.error_txt = error_txt;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetError_txt() {
|
||||
|
|
@ -128,27 +130,13 @@ public class CqlResult implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
}
|
||||
|
||||
public int getResult_setSize() {
|
||||
return (this.result_set == null) ? 0 : this.result_set.size();
|
||||
}
|
||||
|
||||
public java.util.Iterator<Map<String,String>> getResult_setIterator() {
|
||||
return (this.result_set == null) ? null : this.result_set.iterator();
|
||||
}
|
||||
|
||||
public void addToResult_set(Map<String,String> elem) {
|
||||
if (this.result_set == null) {
|
||||
this.result_set = new ArrayList<Map<String,String>>();
|
||||
}
|
||||
this.result_set.add(elem);
|
||||
}
|
||||
|
||||
public List<Map<String,String>> getResult_set() {
|
||||
return this.result_set;
|
||||
}
|
||||
|
||||
public void setResult_set(List<Map<String,String>> result_set) {
|
||||
public CqlResult setResult_set(List<Map<String,String>> result_set) {
|
||||
this.result_set = result_set;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetResult_set() {
|
||||
|
|
|
|||
|
|
@ -66,8 +66,9 @@ public class InvalidRequestException extends Exception implements TBase, java.io
|
|||
return this.why;
|
||||
}
|
||||
|
||||
public void setWhy(String why) {
|
||||
public InvalidRequestException setWhy(String why) {
|
||||
this.why = why;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetWhy() {
|
||||
|
|
|
|||
|
|
@ -79,27 +79,13 @@ public class SlicePredicate implements TBase, java.io.Serializable, Cloneable {
|
|||
return new SlicePredicate(this);
|
||||
}
|
||||
|
||||
public int getColumn_namesSize() {
|
||||
return (this.column_names == null) ? 0 : this.column_names.size();
|
||||
}
|
||||
|
||||
public java.util.Iterator<byte[]> getColumn_namesIterator() {
|
||||
return (this.column_names == null) ? null : this.column_names.iterator();
|
||||
}
|
||||
|
||||
public void addToColumn_names(byte[] elem) {
|
||||
if (this.column_names == null) {
|
||||
this.column_names = new ArrayList<byte[]>();
|
||||
}
|
||||
this.column_names.add(elem);
|
||||
}
|
||||
|
||||
public List<byte[]> getColumn_names() {
|
||||
return this.column_names;
|
||||
}
|
||||
|
||||
public void setColumn_names(List<byte[]> column_names) {
|
||||
public SlicePredicate setColumn_names(List<byte[]> column_names) {
|
||||
this.column_names = column_names;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetColumn_names() {
|
||||
|
|
@ -121,8 +107,9 @@ public class SlicePredicate implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.slice_range;
|
||||
}
|
||||
|
||||
public void setSlice_range(SliceRange slice_range) {
|
||||
public SlicePredicate setSlice_range(SliceRange slice_range) {
|
||||
this.slice_range = slice_range;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetSlice_range() {
|
||||
|
|
@ -281,20 +268,24 @@ public class SlicePredicate implements TBase, java.io.Serializable, Cloneable {
|
|||
|
||||
oprot.writeStructBegin(STRUCT_DESC);
|
||||
if (this.column_names != null) {
|
||||
oprot.writeFieldBegin(COLUMN_NAMES_FIELD_DESC);
|
||||
{
|
||||
oprot.writeListBegin(new TList(TType.STRING, this.column_names.size()));
|
||||
for (byte[] _iter34 : this.column_names) {
|
||||
oprot.writeBinary(_iter34);
|
||||
if (isSetColumn_names()) {
|
||||
oprot.writeFieldBegin(COLUMN_NAMES_FIELD_DESC);
|
||||
{
|
||||
oprot.writeListBegin(new TList(TType.STRING, this.column_names.size()));
|
||||
for (byte[] _iter34 : this.column_names) {
|
||||
oprot.writeBinary(_iter34);
|
||||
}
|
||||
oprot.writeListEnd();
|
||||
}
|
||||
oprot.writeListEnd();
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
if (this.slice_range != null) {
|
||||
oprot.writeFieldBegin(SLICE_RANGE_FIELD_DESC);
|
||||
this.slice_range.write(oprot);
|
||||
oprot.writeFieldEnd();
|
||||
if (isSetSlice_range()) {
|
||||
oprot.writeFieldBegin(SLICE_RANGE_FIELD_DESC);
|
||||
this.slice_range.write(oprot);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
}
|
||||
oprot.writeFieldStop();
|
||||
oprot.writeStructEnd();
|
||||
|
|
|
|||
|
|
@ -104,8 +104,9 @@ public class SliceRange implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.start;
|
||||
}
|
||||
|
||||
public void setStart(byte[] start) {
|
||||
public SliceRange setStart(byte[] start) {
|
||||
this.start = start;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetStart() {
|
||||
|
|
@ -127,8 +128,9 @@ public class SliceRange implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.finish;
|
||||
}
|
||||
|
||||
public void setFinish(byte[] finish) {
|
||||
public SliceRange setFinish(byte[] finish) {
|
||||
this.finish = finish;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetFinish() {
|
||||
|
|
@ -150,9 +152,10 @@ public class SliceRange implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.is_ascending;
|
||||
}
|
||||
|
||||
public void setIs_ascending(boolean is_ascending) {
|
||||
public SliceRange setIs_ascending(boolean is_ascending) {
|
||||
this.is_ascending = is_ascending;
|
||||
this.__isset.is_ascending = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetIs_ascending() {
|
||||
|
|
@ -172,9 +175,10 @@ public class SliceRange implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
public SliceRange setCount(int count) {
|
||||
this.count = count;
|
||||
this.__isset.count = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetCount() {
|
||||
|
|
|
|||
|
|
@ -82,8 +82,9 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(byte[] name) {
|
||||
public SuperColumn setName(byte[] name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetName() {
|
||||
|
|
@ -101,27 +102,13 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
}
|
||||
|
||||
public int getColumnsSize() {
|
||||
return (this.columns == null) ? 0 : this.columns.size();
|
||||
}
|
||||
|
||||
public java.util.Iterator<Column> getColumnsIterator() {
|
||||
return (this.columns == null) ? null : this.columns.iterator();
|
||||
}
|
||||
|
||||
public void addToColumns(Column elem) {
|
||||
if (this.columns == null) {
|
||||
this.columns = new ArrayList<Column>();
|
||||
}
|
||||
this.columns.add(elem);
|
||||
}
|
||||
|
||||
public List<Column> getColumns() {
|
||||
return this.columns;
|
||||
}
|
||||
|
||||
public void setColumns(List<Column> columns) {
|
||||
public SuperColumn setColumns(List<Column> columns) {
|
||||
this.columns = columns;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetColumns() {
|
||||
|
|
|
|||
|
|
@ -146,8 +146,7 @@ public class CliClient
|
|||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
css_.out.printf("Cannot display results (UTF-8 not supported).");
|
||||
break;
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
css_.out.println("Returned " + size + " rows.");
|
||||
|
|
@ -161,14 +160,16 @@ public class CliClient
|
|||
try
|
||||
{
|
||||
cosc = thriftClient_.get(tableName, key, new ColumnPath(columnFamily, null, columnName.getBytes("UTF-8")), ConsistencyLevel.ONE);
|
||||
Column column = cosc.column;
|
||||
css_.out.printf("==> (name=%s, value=%s; timestamp=%d)\n",
|
||||
new String(column.name, "UTF-8"),
|
||||
new String(column.value, "UTF-8"),
|
||||
column.timestamp);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Column column = cosc.column;
|
||||
css_.out.printf("==> (name=%s, value=%s; timestamp=%d)\n",
|
||||
column.name, column.value, column.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
|
||||
/**
|
||||
* BindOperand:
|
||||
* Represents a bind variable in the CQL statement. Lives
|
||||
* in the shared execution plan.
|
||||
*/
|
||||
public class BindOperand implements OperandDef
|
||||
{
|
||||
int bindIndex_; // bind position
|
||||
|
||||
public BindOperand(int bindIndex)
|
||||
{
|
||||
bindIndex_ = bindIndex;
|
||||
}
|
||||
|
||||
public Object get()
|
||||
{
|
||||
// TODO: Once bind variables are supported, the get() will extract
|
||||
// the value of the bind at position "bindIndex_" from the execution
|
||||
// context.
|
||||
throw new RuntimeException(RuntimeErrorMsg.IMPLEMENTATION_RESTRICTION
|
||||
.getMsg("bind params not yet supported"));
|
||||
}
|
||||
|
||||
public String explain()
|
||||
{
|
||||
return "Bind #: " + bindIndex_;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
//Note: This class is CQL related work in progress.
|
||||
public class CExpr
|
||||
{
|
||||
public static interface Expr
|
||||
{
|
||||
CType getType();
|
||||
String toString();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//Note: This class is CQL related work in progress.
|
||||
public class CType
|
||||
{
|
||||
public static interface Type
|
||||
{
|
||||
String toString();
|
||||
};
|
||||
|
||||
public static class IntegerType implements Type
|
||||
{
|
||||
public String toString() { return "Integer"; };
|
||||
}
|
||||
|
||||
public static class StringType implements Type
|
||||
{
|
||||
public String toString() { return "String"; };
|
||||
}
|
||||
|
||||
public static class RowType implements Type
|
||||
{
|
||||
ArrayList<Type> types_;
|
||||
public RowType(ArrayList<Type> types)
|
||||
{
|
||||
types_ = types;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder("<");
|
||||
for (int idx = types_.size(); idx > 0; idx--)
|
||||
{
|
||||
sb.append(types_.toString());
|
||||
if (idx != 1)
|
||||
{
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append(">");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ArrayType
|
||||
{
|
||||
Type elementType_;
|
||||
public ArrayType(Type elementType)
|
||||
{
|
||||
elementType_ = elementType;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Array(" + elementType_.toString() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ColumnMapExpr extends ArrayList<Pair<OperandDef, OperandDef>>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
};
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.service.ConsistencyLevel;
|
||||
import org.apache.cassandra.service.StorageProxy;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
/**
|
||||
* A Row Source Defintion (RSD) for doing a range query on a column map
|
||||
* (in Standard or Super Column Family).
|
||||
*/
|
||||
public class ColumnRangeQueryRSD extends RowSourceDef
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(ColumnRangeQueryRSD.class);
|
||||
private CFMetaData cfMetaData_;
|
||||
private OperandDef rowKey_;
|
||||
private OperandDef superColumnKey_;
|
||||
private int limit_;
|
||||
|
||||
/**
|
||||
* Set up a range query on column map in a simple column family.
|
||||
* The column map in a simple column family is identified by the rowKey.
|
||||
*
|
||||
* Note: "limit" of -1 is the equivalent of no limit.
|
||||
* "offset" specifies the number of rows to skip. An offset of 0 implies from the first row.
|
||||
*/
|
||||
public ColumnRangeQueryRSD(CFMetaData cfMetaData, OperandDef rowKey, int limit)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
superColumnKey_ = null;
|
||||
limit_ = limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a range query on a column map in a super column family.
|
||||
* The column map in a super column family is identified by the rowKey & superColumnKey.
|
||||
*
|
||||
* Note: "limit" of -1 is the equivalent of no limit.
|
||||
* "offset" specifies the number of rows to skip. An offset of 0 implies the first row.
|
||||
*/
|
||||
public ColumnRangeQueryRSD(CFMetaData cfMetaData, ConstantOperand rowKey, ConstantOperand superColumnKey, int limit)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
superColumnKey_ = superColumnKey;
|
||||
limit_ = limit;
|
||||
}
|
||||
|
||||
public List<Map<String,String>> getRows() throws UnsupportedEncodingException
|
||||
{
|
||||
QueryPath path;
|
||||
String superColumnKey = null;
|
||||
|
||||
if (superColumnKey_ != null)
|
||||
{
|
||||
superColumnKey = (String)(superColumnKey_.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey.getBytes("UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
path = new QueryPath(cfMetaData_.cfName);
|
||||
}
|
||||
|
||||
Row row = null;
|
||||
try
|
||||
{
|
||||
String key = (String)(rowKey_.get());
|
||||
ReadCommand readCommand = new SliceFromReadCommand(cfMetaData_.tableName, key, path, ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, limit_);
|
||||
row = StorageProxy.readProtocol(readCommand, ConsistencyLevel.ONE);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger_.error(LogUtil.throwableToString(e));
|
||||
throw new RuntimeException(RuntimeErrorMsg.GENERIC_ERROR.getMsg());
|
||||
}
|
||||
|
||||
List<Map<String, String>> rows = new LinkedList<Map<String, String>>();
|
||||
if (row != null)
|
||||
{
|
||||
ColumnFamily cfamily = row.getColumnFamily(cfMetaData_.cfName);
|
||||
if (cfamily != null)
|
||||
{
|
||||
Collection<IColumn> columns = null;
|
||||
if (superColumnKey_ != null)
|
||||
{
|
||||
// this is the super column case
|
||||
IColumn column = cfamily.getColumn(superColumnKey.getBytes("UTF-8"));
|
||||
if (column != null)
|
||||
columns = column.getSubColumns();
|
||||
}
|
||||
else
|
||||
{
|
||||
columns = cfamily.getSortedColumns();
|
||||
}
|
||||
|
||||
if (columns != null && columns.size() > 0)
|
||||
{
|
||||
for (IColumn column : columns)
|
||||
{
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
|
||||
result.put(cfMetaData_.n_columnKey, new String(column.name(), "UTF-8"));
|
||||
result.put(cfMetaData_.n_columnValue, new String(column.value()));
|
||||
result.put(cfMetaData_.n_columnTimestamp, Long.toString(column.timestamp()));
|
||||
|
||||
rows.add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
public String explainPlan()
|
||||
{
|
||||
return String.format("%s Column Family: Column Range Query: \n" +
|
||||
" Table Name: %s\n" +
|
||||
" Column Family: %s\n" +
|
||||
" RowKey: %s\n" +
|
||||
"%s" +
|
||||
" Limit: %d\n" +
|
||||
" Order By: %s",
|
||||
cfMetaData_.columnType,
|
||||
cfMetaData_.tableName,
|
||||
cfMetaData_.cfName,
|
||||
rowKey_.explain(),
|
||||
(superColumnKey_ == null) ? "" : " SuperColumnKey: " + superColumnKey_.explain() + "\n",
|
||||
limit_,
|
||||
cfMetaData_.comparator);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
/**
|
||||
* ConstantOperand:
|
||||
* Represents a literal/constant operand in the CQL statement.
|
||||
* Lives as part of the shared execution plan.
|
||||
*/
|
||||
public class ConstantOperand implements OperandDef
|
||||
{
|
||||
Object value_;
|
||||
public ConstantOperand(Object value)
|
||||
{
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
public Object get()
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
public String explain()
|
||||
{
|
||||
return "Constant: '" + value_ + "'";
|
||||
}
|
||||
};
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CqlResult
|
||||
{
|
||||
public int errorCode; // 0 - success
|
||||
public String errorTxt;
|
||||
public List<Map<String, String>> resultSet;
|
||||
|
||||
public CqlResult(List<Map<String, String>> rows)
|
||||
{
|
||||
resultSet = rows;
|
||||
errorTxt = null;
|
||||
errorCode = 0; // success
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
/**
|
||||
* This class represents the execution plan for DML (data manipulation language)
|
||||
* CQL statements.
|
||||
*/
|
||||
public abstract class DMLPlan extends Plan {};
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* The "Plan" for the EXPLAIN PLAN statement itself!
|
||||
*
|
||||
* It is nothing but a simple wrapper around the "Plan" for the statement
|
||||
* on which an EXPLAIN PLAN has been requested.
|
||||
*/
|
||||
public class ExplainPlan extends Plan
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(ExplainPlan.class);
|
||||
|
||||
// the execution plan for the statement on which an
|
||||
// EXPLAIN PLAN was requested.
|
||||
private Plan plan_ = null;
|
||||
|
||||
/**
|
||||
* Construct an ExplainPlan instance for the statement whose
|
||||
* "plan" has been passed in.
|
||||
*/
|
||||
public ExplainPlan(Plan plan)
|
||||
{
|
||||
plan_ = plan;
|
||||
}
|
||||
|
||||
public CqlResult execute()
|
||||
{
|
||||
String planText = plan_.explainPlan();
|
||||
|
||||
List<Map<String, String>> rows = new LinkedList<Map<String, String>>();
|
||||
Map<String, String> row = new HashMap<String, String>();
|
||||
row.put("PLAN", planText);
|
||||
rows.add(row);
|
||||
|
||||
return new CqlResult(rows);
|
||||
}
|
||||
|
||||
public String explainPlan()
|
||||
{
|
||||
// We never expect this method to get invoked for ExplainPlan instances
|
||||
// (i.e. those that correspond to the EXPLAIN PLAN statement).
|
||||
logger_.error("explainPlan() invoked on an ExplainPlan instance");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
/**
|
||||
* OperandDef:
|
||||
*
|
||||
* The abstract definition of an operand (i.e. data item) in
|
||||
* CQL compiler/runtime. Examples, include a Constant operand
|
||||
* or a Bind operand. This is the part of an operand definition
|
||||
* that lives in the share-able execution plan.
|
||||
*/
|
||||
public abstract interface OperandDef
|
||||
{
|
||||
public abstract Object get();
|
||||
public abstract String explain();
|
||||
};
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
/* Would have expected java.util.* to have this class!
|
||||
* Code cut-paste from wikipedia.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generic for representing a "typed" 2-tuple.
|
||||
*/
|
||||
public class Pair<T, S>
|
||||
{
|
||||
public Pair(T f, S s)
|
||||
{
|
||||
first = f;
|
||||
second = s;
|
||||
}
|
||||
|
||||
public T getFirst()
|
||||
{
|
||||
return first;
|
||||
}
|
||||
|
||||
public S getSecond()
|
||||
{
|
||||
return second;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "(" + first.toString() + ", " + second.toString() + ")";
|
||||
}
|
||||
|
||||
private T first;
|
||||
private S second;
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* Abstract class representing the shared execution plan for a CQL
|
||||
* statement (query or DML operation).
|
||||
*
|
||||
*/
|
||||
public abstract class Plan
|
||||
{
|
||||
public abstract CqlResult execute() throws UnsupportedEncodingException;
|
||||
public abstract String explainPlan();
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* This class represents the execution plan for Query (data retrieval) statement.
|
||||
*/
|
||||
public class QueryPlan extends Plan
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(QueryPlan.class);
|
||||
|
||||
public RowSourceDef root; // the root of the row source tree
|
||||
|
||||
public QueryPlan(RowSourceDef rwsDef)
|
||||
{
|
||||
root = rwsDef;
|
||||
}
|
||||
|
||||
public CqlResult execute()
|
||||
{
|
||||
if (root != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new CqlResult(root.getRows());
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
else
|
||||
logger_.error("No rowsource to execute");
|
||||
return null;
|
||||
}
|
||||
|
||||
public String explainPlan()
|
||||
{
|
||||
return root.explainPlan();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* The abstract notion of a row source definition. A row source
|
||||
* is literally just anything that returns rows back.
|
||||
*
|
||||
* The concrete implementations of row source might be things like a
|
||||
* column family row source, a "super column family" row source,
|
||||
* a table row source, etc.
|
||||
*
|
||||
* Note: Instances of sub-classes of this class are part of the "shared"
|
||||
* execution plan of CQL. And hence they should not contain any mutable
|
||||
* (i.e. session specific) execution state. Mutable state, such a bind
|
||||
* variable values (corresponding to say a rowKey or a column Key) are
|
||||
* note part of the RowSourceDef tree.
|
||||
*
|
||||
* [Eventually the notion of a "mutable" portion of the RowSource (RowSourceMut)
|
||||
* will be introduced to hold session-specific execution state of the RowSource.
|
||||
* For example, this would be needed when implementing iterator style rowsources
|
||||
* that yields rows back one at a time as opposed to returning them in one
|
||||
* shot.]
|
||||
*/
|
||||
public abstract class RowSourceDef
|
||||
{
|
||||
public abstract List<Map<String,String>> getRows() throws UnsupportedEncodingException;
|
||||
public abstract String explainPlan();
|
||||
}
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
import org.apache.cassandra.db.RowMutation;
|
||||
import org.apache.cassandra.service.StorageProxy;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cassandra.cql.execution.*;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.service.*;
|
||||
|
||||
/**
|
||||
* Execution plan for batch setting a set of columns in a Simple/Super column family.
|
||||
* SET table.standard_cf[<rowKey>] = <columnMapExpr>;
|
||||
* SET table.super_cf[<rowKey>][<superColumn>] = <columnMapExpr>;
|
||||
*/
|
||||
public class SetColumnMap extends DMLPlan
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(SetUniqueKey.class);
|
||||
private CFMetaData cfMetaData_;
|
||||
private OperandDef rowKey_;
|
||||
private OperandDef superColumnKey_;
|
||||
private ColumnMapExpr columnMapExpr_;
|
||||
|
||||
/**
|
||||
* construct an execution plan node to set the column map for a Standard Column Family.
|
||||
*
|
||||
* SET table.standard_cf[<rowKey>] = <columnMapExpr>;
|
||||
*/
|
||||
public SetColumnMap(CFMetaData cfMetaData, OperandDef rowKey, ColumnMapExpr columnMapExpr)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
superColumnKey_ = null;
|
||||
columnMapExpr_ = columnMapExpr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an execution plan node to set the column map for a Super Column Family
|
||||
*
|
||||
* SET table.super_cf[<rowKey>][<superColumn>] = <columnMapExpr>;
|
||||
*/
|
||||
public SetColumnMap(CFMetaData cfMetaData, OperandDef rowKey, OperandDef superColumnKey, ColumnMapExpr columnMapExpr)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
superColumnKey_ = superColumnKey;
|
||||
columnMapExpr_ = columnMapExpr;
|
||||
}
|
||||
|
||||
public CqlResult execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
RowMutation rm = new RowMutation(cfMetaData_.tableName, (String)(rowKey_.get()));
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
for (Pair<OperandDef, OperandDef> entry : columnMapExpr_)
|
||||
{
|
||||
OperandDef columnKey = entry.getFirst();
|
||||
OperandDef value = entry.getSecond();
|
||||
|
||||
QueryPath path;
|
||||
if (superColumnKey_ != null)
|
||||
{
|
||||
String superColumnKey = (String)(superColumnKey_.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey.getBytes("UTF-8"), ((String)columnKey.get()).getBytes("UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
path = new QueryPath(cfMetaData_.cfName, null, ((String)columnKey.get()).getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
rm.add(path, ((String)value.get()).getBytes(), time);
|
||||
}
|
||||
StorageProxy.insert(rm);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger_.error(LogUtil.throwableToString(e));
|
||||
throw new RuntimeException(RuntimeErrorMsg.GENERIC_ERROR.getMsg());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String explainPlan()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String prefix =
|
||||
String.format("%s Column Family: Batch SET a set of columns: \n" +
|
||||
" Table Name: %s\n" +
|
||||
" Column Famly: %s\n" +
|
||||
" RowKey: %s\n" +
|
||||
"%s",
|
||||
cfMetaData_.columnType,
|
||||
cfMetaData_.tableName,
|
||||
cfMetaData_.cfName,
|
||||
rowKey_.explain(),
|
||||
(superColumnKey_ == null) ? "" : " SuperColumnKey: " + superColumnKey_.explain() + "\n");
|
||||
|
||||
for (Pair<OperandDef, OperandDef> entry : columnMapExpr_)
|
||||
{
|
||||
OperandDef columnKey = entry.getFirst();
|
||||
OperandDef value = entry.getSecond();
|
||||
sb.append(String.format(" ColumnKey: %s\n" +
|
||||
" Value: %s\n",
|
||||
columnKey.explain(), value.explain()));
|
||||
}
|
||||
|
||||
return prefix + sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,119 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
import org.apache.cassandra.db.RowMutation;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.service.StorageProxy;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cassandra.cql.execution.*;
|
||||
|
||||
/**
|
||||
* Execution plan for batch setting a set of super columns in a Super column family.
|
||||
* SET table.super_cf[<rowKey>] = <superColumnMapExpr>;
|
||||
*/
|
||||
public class SetSuperColumnMap extends DMLPlan
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(SetUniqueKey.class);
|
||||
private CFMetaData cfMetaData_;
|
||||
private OperandDef rowKey_;
|
||||
private SuperColumnMapExpr superColumnMapExpr_;
|
||||
|
||||
/**
|
||||
* construct an execution plan node to batch set a bunch of super columns in a
|
||||
* super column family.
|
||||
*
|
||||
* SET table.super_cf[<rowKey>] = <superColumnMapExpr>;
|
||||
*/
|
||||
public SetSuperColumnMap(CFMetaData cfMetaData, OperandDef rowKey, SuperColumnMapExpr superColumnMapExpr)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
superColumnMapExpr_ = superColumnMapExpr;
|
||||
}
|
||||
|
||||
public CqlResult execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
RowMutation rm = new RowMutation(cfMetaData_.tableName, (String)(rowKey_.get()));
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
for (Pair<OperandDef, ColumnMapExpr> superColumn : superColumnMapExpr_)
|
||||
{
|
||||
OperandDef superColumnKey = superColumn.getFirst();
|
||||
ColumnMapExpr columnMapExpr = superColumn.getSecond();
|
||||
|
||||
for (Pair<OperandDef, OperandDef> entry : columnMapExpr)
|
||||
{
|
||||
OperandDef columnKey = entry.getFirst();
|
||||
OperandDef value = entry.getSecond();
|
||||
QueryPath path = new QueryPath(cfMetaData_.cfName, ((String)(superColumnKey.get())).getBytes("UTF-8"), ((String)(columnKey.get())).getBytes("UTF-8"));
|
||||
rm.add(path, ((String)value.get()).getBytes(), time);
|
||||
}
|
||||
}
|
||||
StorageProxy.insert(rm);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger_.error(LogUtil.throwableToString(e));
|
||||
throw new RuntimeException(RuntimeErrorMsg.GENERIC_ERROR.getMsg());
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public String explainPlan()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String prefix =
|
||||
String.format("%s Column Family: Batch SET a set of Super Columns: \n" +
|
||||
" Table Name: %s\n" +
|
||||
" Column Famly: %s\n" +
|
||||
" RowKey: %s\n",
|
||||
cfMetaData_.columnType,
|
||||
cfMetaData_.tableName,
|
||||
cfMetaData_.cfName,
|
||||
rowKey_.explain());
|
||||
|
||||
for (Pair<OperandDef, ColumnMapExpr> superColumn : superColumnMapExpr_)
|
||||
{
|
||||
OperandDef superColumnKey = superColumn.getFirst();
|
||||
ColumnMapExpr columnMapExpr = superColumn.getSecond();
|
||||
|
||||
for (Pair<OperandDef, OperandDef> entry : columnMapExpr)
|
||||
{
|
||||
OperandDef columnKey = entry.getFirst();
|
||||
OperandDef value = entry.getSecond();
|
||||
sb.append(String.format(" SuperColumnKey: %s\n" +
|
||||
" ColumnKey: %s\n" +
|
||||
" Value: %s\n",
|
||||
superColumnKey.explain(),
|
||||
columnKey.explain(),
|
||||
value.explain()));
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
import org.apache.cassandra.db.RowMutation;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.service.StorageProxy;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Execution plan for setting a specific column in a Simple/Super column family.
|
||||
* SET table.standard_cf[<rowKey>][<columnKey>] = <value>;
|
||||
* SET table.super_cf[<rowKey>][<superColumnKey>][<columnKey>] = <value>;
|
||||
*/
|
||||
public class SetUniqueKey extends DMLPlan
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(SetUniqueKey.class);
|
||||
private CFMetaData cfMetaData_;
|
||||
private OperandDef rowKey_;
|
||||
private OperandDef superColumnKey_;
|
||||
private OperandDef columnKey_;
|
||||
private OperandDef value_;
|
||||
|
||||
/**
|
||||
* Construct an execution plan for setting a column in a simple column family
|
||||
*
|
||||
* SET table.standard_cf[<rowKey>][<columnKey>] = <value>;
|
||||
*/
|
||||
public SetUniqueKey(CFMetaData cfMetaData, OperandDef rowKey, OperandDef columnKey, OperandDef value)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
columnKey_ = columnKey;
|
||||
superColumnKey_ = null;
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct execution plan for setting a column in a super column family.
|
||||
*
|
||||
* SET table.super_cf[<rowKey>][<superColumnKey>][<columnKey>] = <value>;
|
||||
*/
|
||||
public SetUniqueKey(CFMetaData cfMetaData, OperandDef rowKey, OperandDef superColumnKey, OperandDef columnKey, OperandDef value)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
superColumnKey_ = superColumnKey;
|
||||
columnKey_ = columnKey;
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
public CqlResult execute() throws UnsupportedEncodingException
|
||||
{
|
||||
String columnKey = (String)(columnKey_.get());
|
||||
QueryPath path;
|
||||
|
||||
if (superColumnKey_ != null)
|
||||
{
|
||||
String superColumnKey = (String)(superColumnKey_.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey.getBytes("UTF-8"), columnKey.getBytes("UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
path = new QueryPath(cfMetaData_.cfName, null, columnKey.getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
RowMutation rm = new RowMutation(cfMetaData_.tableName, (String)(rowKey_.get()));
|
||||
rm.add(path, ((String)value_.get()).getBytes(), System.currentTimeMillis());
|
||||
StorageProxy.insert(rm);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger_.error(LogUtil.throwableToString(e));
|
||||
throw new RuntimeException(RuntimeErrorMsg.GENERIC_ERROR.getMsg());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String explainPlan()
|
||||
{
|
||||
return
|
||||
String.format("%s Column Family: Unique Key SET: \n" +
|
||||
" Table Name: %s\n" +
|
||||
" Column Famly: %s\n" +
|
||||
" RowKey: %s\n" +
|
||||
"%s" +
|
||||
" ColumnKey: %s\n" +
|
||||
" Value: %s\n",
|
||||
cfMetaData_.columnType,
|
||||
cfMetaData_.tableName,
|
||||
cfMetaData_.cfName,
|
||||
rowKey_.explain(),
|
||||
(superColumnKey_ == null) ? "" : " SuperColumnKey: " + superColumnKey_.explain() + "\n",
|
||||
columnKey_.explain(),
|
||||
value_.explain());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SuperColumnMapExpr extends ArrayList<Pair<OperandDef, ColumnMapExpr>>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
};
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.service.ConsistencyLevel;
|
||||
import org.apache.cassandra.service.StorageProxy;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
/**
|
||||
* A Row Source Definition (RSD) for doing a super column range query on a Super Column Family.
|
||||
*/
|
||||
public class SuperColumnRangeQueryRSD extends RowSourceDef
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(SuperColumnRangeQueryRSD.class);
|
||||
private CFMetaData cfMetaData_;
|
||||
private OperandDef rowKey_;
|
||||
private int limit_;
|
||||
|
||||
/**
|
||||
* Set up a range query on super column map in a super column family.
|
||||
* The super column map is identified by the rowKey.
|
||||
*
|
||||
* Note: "limit" of -1 is the equivalent of no limit.
|
||||
* "offset" specifies the number of rows to skip.
|
||||
* An offset of 0 implies from the first row.
|
||||
*/
|
||||
public SuperColumnRangeQueryRSD(CFMetaData cfMetaData, OperandDef rowKey, int limit)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
limit_ = limit;
|
||||
}
|
||||
|
||||
public List<Map<String,String>> getRows() throws UnsupportedEncodingException
|
||||
{
|
||||
Row row = null;
|
||||
try
|
||||
{
|
||||
String key = (String)(rowKey_.get());
|
||||
ReadCommand readCommand = new SliceFromReadCommand(cfMetaData_.tableName, key, new QueryPath(cfMetaData_.cfName), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, limit_);
|
||||
row = StorageProxy.readProtocol(readCommand, ConsistencyLevel.ONE);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger_.error(LogUtil.throwableToString(e));
|
||||
throw new RuntimeException(RuntimeErrorMsg.GENERIC_ERROR.getMsg());
|
||||
}
|
||||
|
||||
List<Map<String, String>> rows = new LinkedList<Map<String, String>>();
|
||||
if (row != null)
|
||||
{
|
||||
ColumnFamily cfamily = row.getColumnFamily(cfMetaData_.cfName);
|
||||
if (cfamily != null)
|
||||
{
|
||||
Collection<IColumn> columns = cfamily.getSortedColumns();
|
||||
if (columns != null && columns.size() > 0)
|
||||
{
|
||||
for (IColumn column : columns)
|
||||
{
|
||||
Collection<IColumn> subColumns = column.getSubColumns();
|
||||
for( IColumn subColumn : subColumns )
|
||||
{
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put(cfMetaData_.n_superColumnKey, new String(column.name(), "UTF-8"));
|
||||
result.put(cfMetaData_.n_columnKey, new String(subColumn.name(), "UTF-8"));
|
||||
result.put(cfMetaData_.n_columnValue, new String(subColumn.value()));
|
||||
result.put(cfMetaData_.n_columnTimestamp, Long.toString(subColumn.timestamp()));
|
||||
rows.add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
public String explainPlan()
|
||||
{
|
||||
return String.format("%s Column Family: Super Column Range Query: \n" +
|
||||
" Table Name: %s\n" +
|
||||
" Column Family: %s\n" +
|
||||
" RowKey: %s\n" +
|
||||
" Limit: %d\n" +
|
||||
" Order By: %s",
|
||||
cfMetaData_.columnType,
|
||||
cfMetaData_.tableName,
|
||||
cfMetaData_.cfName,
|
||||
rowKey_.explain(),
|
||||
limit_,
|
||||
cfMetaData_.comparator);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.service.ConsistencyLevel;
|
||||
import org.apache.cassandra.service.StorageProxy;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* A Row Source Defintion (RSD) for looking up a unique column within a column family.
|
||||
*/
|
||||
public class UniqueKeyQueryRSD extends RowSourceDef
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(UniqueKeyQueryRSD.class);
|
||||
private CFMetaData cfMetaData_;
|
||||
private OperandDef rowKey_;
|
||||
private OperandDef superColumnKey_;
|
||||
private OperandDef columnKey_;
|
||||
|
||||
// super column family
|
||||
public UniqueKeyQueryRSD(CFMetaData cfMetaData, OperandDef rowKey, OperandDef superColumnKey, OperandDef columnKey)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
superColumnKey_ = superColumnKey;
|
||||
columnKey_ = columnKey;
|
||||
}
|
||||
|
||||
// simple column family
|
||||
public UniqueKeyQueryRSD(CFMetaData cfMetaData, OperandDef rowKey, OperandDef columnKey)
|
||||
{
|
||||
cfMetaData_ = cfMetaData;
|
||||
rowKey_ = rowKey;
|
||||
columnKey_ = columnKey;
|
||||
superColumnKey_ = null;
|
||||
}
|
||||
|
||||
// specific column lookup
|
||||
public List<Map<String,String>> getRows() throws UnsupportedEncodingException
|
||||
{
|
||||
String columnKey = (String)(columnKey_.get());
|
||||
QueryPath path = null;
|
||||
String superColumnKey = null;
|
||||
|
||||
if (superColumnKey_ != null)
|
||||
{
|
||||
superColumnKey = (String)(superColumnKey_.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey.getBytes("UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
path = new QueryPath(cfMetaData_.cfName);
|
||||
}
|
||||
|
||||
Row row = null;
|
||||
try
|
||||
{
|
||||
String key = (String)(rowKey_.get());
|
||||
ReadCommand readCommand = new SliceByNamesReadCommand(cfMetaData_.tableName, key, path, Arrays.asList(columnKey.getBytes("UTF-8")));
|
||||
row = StorageProxy.readProtocol(readCommand, ConsistencyLevel.ONE);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger_.error(LogUtil.throwableToString(e));
|
||||
throw new RuntimeException(RuntimeErrorMsg.GENERIC_ERROR.getMsg());
|
||||
}
|
||||
|
||||
if (row != null)
|
||||
{
|
||||
ColumnFamily cfamily = row.getColumnFamily(cfMetaData_.cfName);
|
||||
if (cfamily != null)
|
||||
{
|
||||
Collection<IColumn> columns = null;
|
||||
if (superColumnKey_ != null)
|
||||
{
|
||||
// this is the super column case
|
||||
IColumn column = cfamily.getColumn(superColumnKey.getBytes("UTF-8"));
|
||||
if (column != null)
|
||||
columns = column.getSubColumns();
|
||||
}
|
||||
else
|
||||
{
|
||||
columns = cfamily.getSortedColumns();
|
||||
}
|
||||
|
||||
if (columns != null && columns.size() > 0)
|
||||
{
|
||||
if (columns.size() > 1)
|
||||
{
|
||||
// We are looking up by a rowKey & columnKey. There should
|
||||
// be at most one column that matches. If we find more than
|
||||
// one, then it is an internal error.
|
||||
throw new RuntimeException(RuntimeErrorMsg.INTERNAL_ERROR.getMsg("Too many columns found for: " + columnKey));
|
||||
}
|
||||
for (IColumn column : columns)
|
||||
{
|
||||
List<Map<String, String>> rows = new LinkedList<Map<String, String>>();
|
||||
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put(cfMetaData_.n_columnKey, new String(column.name(), "UTF-8"));
|
||||
result.put(cfMetaData_.n_columnValue, new String(column.value()));
|
||||
result.put(cfMetaData_.n_columnTimestamp, Long.toString(column.timestamp()));
|
||||
|
||||
rows.add(result);
|
||||
|
||||
// at this point, due to the prior checks, we are guaranteed that
|
||||
// there is only one item in "columns".
|
||||
return rows;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException(RuntimeErrorMsg.NO_DATA_FOUND.getMsg());
|
||||
}
|
||||
|
||||
public String explainPlan()
|
||||
{
|
||||
return String.format("%s Column Family: Unique Key Query: \n" +
|
||||
" Table Name: %s\n" +
|
||||
" Column Famly: %s\n" +
|
||||
" RowKey: %s\n" +
|
||||
"%s" +
|
||||
" ColumnKey: %s",
|
||||
cfMetaData_.columnType,
|
||||
cfMetaData_.tableName,
|
||||
cfMetaData_.cfName,
|
||||
rowKey_.explain(),
|
||||
(superColumnKey_ == null) ? "" : " SuperColumnKey: " + superColumnKey_.explain() + "\n",
|
||||
columnKey_.explain());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.common;
|
||||
|
||||
public class Utils
|
||||
{
|
||||
/*
|
||||
* Strips leading and trailing "'" characters, and handles
|
||||
* and escaped characters such as \n, \r, etc.
|
||||
* [Shameless clone from hive.]
|
||||
*/
|
||||
public static String unescapeSQLString(String b)
|
||||
{
|
||||
assert(b.charAt(0) == '\'');
|
||||
assert(b.charAt(b.length()-1) == '\'');
|
||||
StringBuilder sb = new StringBuilder(b.length());
|
||||
|
||||
for (int i=1; i+1<b.length(); i++)
|
||||
{
|
||||
if (b.charAt(i) == '\\' && i+2<b.length())
|
||||
{
|
||||
char n=b.charAt(i+1);
|
||||
switch(n)
|
||||
{
|
||||
case '0': sb.append("\0"); break;
|
||||
case '\'': sb.append("'"); break;
|
||||
case '"': sb.append("\""); break;
|
||||
case 'b': sb.append("\b"); break;
|
||||
case 'n': sb.append("\n"); break;
|
||||
case 'r': sb.append("\r"); break;
|
||||
case 't': sb.append("\t"); break;
|
||||
case 'Z': sb.append("\u001A"); break;
|
||||
case '\\': sb.append("\\"); break;
|
||||
case '%': sb.append("%"); break;
|
||||
case '_': sb.append("_"); break;
|
||||
default: sb.append(n);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append(b.charAt(i));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.compiler.common;
|
||||
|
||||
import org.antlr.runtime.tree.CommonTree;
|
||||
|
||||
/**
|
||||
* List of error messages thrown by the CQL Compiler
|
||||
**/
|
||||
|
||||
public enum CompilerErrorMsg
|
||||
{
|
||||
// Error messages with String.format() style format specifiers
|
||||
GENERIC_ERROR("CQL Compilation Error"),
|
||||
INTERNAL_ERROR("CQL Compilation Internal Error"),
|
||||
INVALID_TABLE("Table '%s' does not exist"),
|
||||
INVALID_COLUMN_FAMILY("Column Family '%s' not found in table '%s'"),
|
||||
TOO_MANY_DIMENSIONS("Too many dimensions specified for %s Column Family"),
|
||||
INVALID_TYPE("Expression is of invalid type")
|
||||
;
|
||||
|
||||
private String mesg;
|
||||
CompilerErrorMsg(String mesg)
|
||||
{
|
||||
this.mesg = mesg;
|
||||
}
|
||||
|
||||
private static String getLineAndPosition(CommonTree tree)
|
||||
{
|
||||
if (tree.getChildCount() == 0)
|
||||
{
|
||||
return tree.getToken().getLine() + ":" + tree.getToken().getCharPositionInLine();
|
||||
}
|
||||
return getLineAndPosition((CommonTree)tree.getChild(0));
|
||||
}
|
||||
|
||||
// Returns the formatted error message. Derives line/position information
|
||||
// from the "tree" node passed in.
|
||||
public String getMsg(CommonTree tree, Object... args)
|
||||
{
|
||||
// We allocate another array since we want to add line and position as an
|
||||
// implicit additional first argument to pass on to String.format.
|
||||
Object[] newArgs = new Object[args.length + 1];
|
||||
newArgs[0] = getLineAndPosition(tree);
|
||||
System.arraycopy(args, 0, newArgs, 1, args.length);
|
||||
|
||||
// note: mesg itself might contain other format specifiers...
|
||||
return String.format("line %s " + mesg, newArgs);
|
||||
}
|
||||
|
||||
String getMsg()
|
||||
{
|
||||
return mesg;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.compiler.common;
|
||||
|
||||
|
||||
import org.apache.cassandra.cql.common.*;
|
||||
import org.apache.cassandra.cql.compiler.parse.*;
|
||||
import org.apache.cassandra.cql.compiler.sem.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.antlr.runtime.*;
|
||||
import org.antlr.runtime.tree.*;
|
||||
import org.apache.cassandra.cql.common.Plan;
|
||||
import org.apache.cassandra.cql.compiler.parse.CqlLexer;
|
||||
import org.apache.cassandra.cql.compiler.parse.CqlParser;
|
||||
import org.apache.cassandra.cql.compiler.parse.ParseError;
|
||||
import org.apache.cassandra.cql.compiler.parse.ParseException;
|
||||
import org.apache.cassandra.cql.compiler.sem.SemanticException;
|
||||
import org.apache.cassandra.cql.compiler.sem.SemanticPhase;
|
||||
|
||||
public class CqlCompiler
|
||||
{
|
||||
// ANTLR does not provide case-insensitive tokenization support
|
||||
// out of the box. So we override the LA (lookahead) function
|
||||
// of the ANTLRStringStream class. Note: This doesn't change the
|
||||
// token text-- but just relaxes the matching rules to match
|
||||
// in upper case. [Logic borrowed from Hive code.]
|
||||
//
|
||||
// Also see discussion on this topic in:
|
||||
// http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782.
|
||||
public class ANTLRNoCaseStringStream extends ANTLRStringStream
|
||||
{
|
||||
public ANTLRNoCaseStringStream(String input)
|
||||
{
|
||||
super(input);
|
||||
}
|
||||
|
||||
public int LA(int i)
|
||||
{
|
||||
int returnChar = super.LA(i);
|
||||
if (returnChar == CharStream.EOF)
|
||||
{
|
||||
return returnChar;
|
||||
}
|
||||
else if (returnChar == 0)
|
||||
{
|
||||
return returnChar;
|
||||
}
|
||||
|
||||
return Character.toUpperCase((char)returnChar);
|
||||
}
|
||||
}
|
||||
|
||||
// Override CQLParser. This gives flexibility in altering default error
|
||||
// messages as well as accumulating multiple errors.
|
||||
public class CqlParserX extends CqlParser
|
||||
{
|
||||
private ArrayList<ParseError> errors;
|
||||
|
||||
public CqlParserX(TokenStream input)
|
||||
{
|
||||
super(input);
|
||||
errors = new ArrayList<ParseError>();
|
||||
}
|
||||
|
||||
protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException
|
||||
{
|
||||
throw new MismatchedTokenException(ttype, input);
|
||||
}
|
||||
|
||||
public Object recoverFromMismatchedSet(IntStream input,
|
||||
RecognitionException re,
|
||||
BitSet follow) throws RecognitionException
|
||||
{
|
||||
throw re;
|
||||
}
|
||||
|
||||
public void displayRecognitionError(String[] tokenNames,
|
||||
RecognitionException e)
|
||||
{
|
||||
errors.add(new ParseError(this, e, tokenNames));
|
||||
}
|
||||
|
||||
public ArrayList<ParseError> getErrors()
|
||||
{
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
// Compile a CQL query
|
||||
public Plan compileQuery(String query) throws ParseException, SemanticException
|
||||
{
|
||||
CommonTree queryTree = null;
|
||||
CqlLexer lexer = null;
|
||||
CqlParserX parser = null;
|
||||
CommonTokenStream tokens = null;
|
||||
|
||||
ANTLRStringStream input = new ANTLRNoCaseStringStream(query);
|
||||
|
||||
lexer = new CqlLexer(input);
|
||||
tokens = new CommonTokenStream(lexer);
|
||||
parser = new CqlParserX(tokens);
|
||||
|
||||
// built AST
|
||||
try
|
||||
{
|
||||
queryTree = (CommonTree)(parser.root().getTree());
|
||||
}
|
||||
catch (RecognitionException e)
|
||||
{
|
||||
throw new ParseException(parser.getErrors());
|
||||
}
|
||||
catch (RewriteEmptyStreamException e)
|
||||
{
|
||||
throw new ParseException(parser.getErrors());
|
||||
}
|
||||
|
||||
if (!parser.getErrors().isEmpty())
|
||||
{
|
||||
throw new ParseException(parser.getErrors());
|
||||
}
|
||||
|
||||
if (!parser.errors.isEmpty())
|
||||
{
|
||||
throw new ParseException("parser error");
|
||||
}
|
||||
|
||||
// Semantic analysis and code-gen.
|
||||
// Eventually, I anticipate, I'll be forking these off into two separate phases.
|
||||
return SemanticPhase.doSemanticAnalysis(queryTree);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,308 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
|
||||
// ANTLR Grammar Definition for Cassandra Query Language (CQL)
|
||||
//
|
||||
// CQL is a query language tailored for Cassandra's multi-level (or
|
||||
// nested-table like) data model where values stored for each key
|
||||
// can be:
|
||||
//
|
||||
// * a simple column map (a 1-level nested table). This is the case
|
||||
// for a simple column family.
|
||||
//
|
||||
// or,
|
||||
//
|
||||
// * a supercolumn column map, which in turn contains a column map
|
||||
// per super column (i.e. a 2-level nested table). This is the case
|
||||
// for a super column family.
|
||||
//
|
||||
// For the common case of key-based data retrieval or storage, CQL
|
||||
// provides array like get/set syntax, such as:
|
||||
//
|
||||
// SET user.profile['99']['name'] = 'joe';
|
||||
// SET user.profile['99']['age'] = '27';
|
||||
// GET user.profile['99']['name'];
|
||||
// GET user.profile['99'];
|
||||
//
|
||||
// When additional constraints need to be applied to data being retrieved
|
||||
// (such as imposing row limits, retrieving counts, retrieving data for
|
||||
// a subset of super columns or columns and son on) CQL falls back to more
|
||||
// traditional SQL-like syntax.
|
||||
//
|
||||
// *Note*: The SQL syntax supported by CQL doesn't support the full
|
||||
// relational algebra. For example, it doesn't have any support for
|
||||
// joins. It also imposes restrictions on the types of filters and ORDER
|
||||
// BY clauses it supports-- generally only those queries that can be
|
||||
// efficiently answered based on data layout are supported. Suppose a column
|
||||
// family has been configured to store columns in time sorted fashion,
|
||||
// CQL will not support 'ORDER BY column_name' for such a column family.
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// NOTE: The grammar is in a very rudimentary/prototypish shape right now.
|
||||
// Will undergo fairly big restructuring in the next checkin.
|
||||
//
|
||||
|
||||
grammar Cql;
|
||||
|
||||
options {
|
||||
output=AST;
|
||||
ASTLabelType=CommonTree;
|
||||
backtrack=true;
|
||||
}
|
||||
|
||||
//
|
||||
// AST Nodes. We use a A_ prefix convention for these AST node names.
|
||||
//
|
||||
tokens {
|
||||
|
||||
// Top-level AST nodes
|
||||
// These typically correspond to various top-level CQL statements.
|
||||
A_DELETE;
|
||||
A_GET;
|
||||
A_SELECT;
|
||||
A_SET;
|
||||
A_EXPLAIN_PLAN;
|
||||
|
||||
// Internal AST nodes
|
||||
A_COLUMN_ACCESS;
|
||||
A_COLUMN_MAP_ENTRY;
|
||||
A_COLUMN_MAP_VALUE;
|
||||
A_FROM;
|
||||
A_KEY_IN_LIST;
|
||||
A_KEY_EXACT_MATCH;
|
||||
A_LIMIT;
|
||||
A_OFFSET;
|
||||
A_ORDER_BY;
|
||||
A_SUPERCOLUMN_MAP_ENTRY;
|
||||
A_SUPERCOLUMN_MAP_VALUE;
|
||||
A_SELECT_CLAUSE;
|
||||
A_WHERE;
|
||||
}
|
||||
|
||||
@parser::header {
|
||||
package org.apache.cassandra.cql.compiler.parse;
|
||||
}
|
||||
|
||||
@lexer::header {
|
||||
package org.apache.cassandra.cql.compiler.parse;
|
||||
}
|
||||
|
||||
//
|
||||
// Parser Section
|
||||
//
|
||||
|
||||
// the root node
|
||||
root
|
||||
: stmt SEMICOLON? EOF -> stmt
|
||||
| K_EXPLAIN K_PLAN stmt SEMICOLON? EOF -> ^(A_EXPLAIN_PLAN stmt)
|
||||
;
|
||||
|
||||
stmt
|
||||
: deleteStmt
|
||||
| getStmt
|
||||
| selectStmt
|
||||
| setStmt
|
||||
;
|
||||
|
||||
getStmt
|
||||
: K_GET columnSpec -> ^(A_GET columnSpec)
|
||||
;
|
||||
|
||||
setStmt
|
||||
: K_SET columnSpec '=' valueExpr -> ^(A_SET columnSpec valueExpr)
|
||||
;
|
||||
|
||||
selectStmt
|
||||
: selectClause
|
||||
fromClause?
|
||||
whereClause?
|
||||
limitClause? -> ^(A_SELECT selectClause fromClause? whereClause? limitClause?)
|
||||
;
|
||||
|
||||
selectClause
|
||||
: K_SELECT selectList -> ^(A_SELECT_CLAUSE selectList)
|
||||
;
|
||||
|
||||
selectList
|
||||
: selectListItem (',' selectListItem)*
|
||||
;
|
||||
|
||||
selectListItem
|
||||
: columnExpression
|
||||
| '(' selectStmt ')' -> ^(A_SELECT selectStmt)
|
||||
;
|
||||
|
||||
columnExpression
|
||||
: columnOrSuperColumnName columnExpressionRest;
|
||||
|
||||
columnExpressionRest
|
||||
: /* empty */
|
||||
| '[' stringVal ']' columnExpressionRest
|
||||
;
|
||||
|
||||
tableExpression
|
||||
: tableName '.' columnFamilyName '[' stringVal ']';
|
||||
|
||||
fromClause
|
||||
: K_FROM tableExpression -> ^(A_FROM tableExpression)
|
||||
;
|
||||
|
||||
whereClause
|
||||
: K_WHERE keyInClause -> ^(A_WHERE keyInClause)
|
||||
| K_WHERE keyExactMatch -> ^(A_WHERE keyExactMatch)
|
||||
;
|
||||
|
||||
keyInClause
|
||||
: columnOrSuperColumnName K_IN '(' a+=stringVal (',' a+=stringVal)* ')'
|
||||
-> ^(A_KEY_IN_LIST columnOrSuperColumnName $a+)
|
||||
;
|
||||
|
||||
keyExactMatch
|
||||
: columnOrSuperColumnName '=' stringVal
|
||||
-> ^(A_KEY_EXACT_MATCH columnOrSuperColumnName stringVal)
|
||||
;
|
||||
|
||||
limitClause
|
||||
: K_LIMIT IntegerLiteral -> ^(A_LIMIT IntegerLiteral);
|
||||
|
||||
deleteStmt
|
||||
: K_DELETE columnSpec -> ^(A_DELETE columnSpec)
|
||||
;
|
||||
|
||||
columnSpec
|
||||
: tableName '.' columnFamilyName '[' rowKey ']'
|
||||
( '[' a+=columnOrSuperColumnKey ']'
|
||||
('[' a+=columnOrSuperColumnKey ']')?
|
||||
)?
|
||||
-> ^(A_COLUMN_ACCESS tableName columnFamilyName rowKey ($a+)?)
|
||||
;
|
||||
|
||||
tableName: Identifier;
|
||||
|
||||
columnFamilyName: Identifier;
|
||||
|
||||
valueExpr
|
||||
: cellValue
|
||||
| columnMapValue
|
||||
| superColumnMapValue
|
||||
;
|
||||
|
||||
cellValue
|
||||
: stringVal;
|
||||
|
||||
columnMapValue
|
||||
: LEFT_BRACE columnMapEntry (COMMA columnMapEntry)* RIGHT_BRACE
|
||||
-> ^(A_COLUMN_MAP_VALUE columnMapEntry+)
|
||||
;
|
||||
|
||||
superColumnMapValue
|
||||
: LEFT_BRACE superColumnMapEntry (COMMA superColumnMapEntry)* RIGHT_BRACE
|
||||
-> ^(A_SUPERCOLUMN_MAP_VALUE superColumnMapEntry+)
|
||||
;
|
||||
|
||||
columnMapEntry
|
||||
: columnKey ASSOC cellValue -> ^(A_COLUMN_MAP_ENTRY columnKey cellValue)
|
||||
;
|
||||
|
||||
superColumnMapEntry
|
||||
: superColumnKey ASSOC columnMapValue -> ^(A_SUPERCOLUMN_MAP_ENTRY superColumnKey columnMapValue)
|
||||
;
|
||||
|
||||
columnOrSuperColumnName: Identifier;
|
||||
|
||||
rowKey: stringVal;
|
||||
columnOrSuperColumnKey: stringVal;
|
||||
columnKey: stringVal;
|
||||
superColumnKey: stringVal;
|
||||
|
||||
// String Values can either be query params (aka bind variables)
|
||||
// or string literals.
|
||||
stringVal
|
||||
: '?' // bind variable
|
||||
| StringLiteral //
|
||||
;
|
||||
|
||||
//
|
||||
// Lexer Section
|
||||
//
|
||||
|
||||
// Keywords (in alphabetical order for convenience)
|
||||
K_BY: 'BY';
|
||||
K_DELETE: 'DELETE';
|
||||
K_EXPLAIN: 'EXPLAIN';
|
||||
K_FROM: 'FROM';
|
||||
K_GET: 'GET';
|
||||
K_IN: 'IN';
|
||||
K_LIMIT: 'LIMIT';
|
||||
K_OFFSET: 'OFFSET';
|
||||
K_ORDER: 'ORDER';
|
||||
K_PLAN: 'PLAN';
|
||||
K_SELECT: 'SELECT';
|
||||
K_SET: 'SET';
|
||||
K_WHERE: 'WHERE';
|
||||
|
||||
// private syntactic rules
|
||||
fragment
|
||||
Letter
|
||||
: 'a'..'z'
|
||||
| 'A'..'Z'
|
||||
;
|
||||
|
||||
fragment
|
||||
Digit
|
||||
: '0'..'9'
|
||||
;
|
||||
|
||||
// syntactic Elements
|
||||
Identifier
|
||||
: Letter ( Letter | Digit | '_')*
|
||||
;
|
||||
|
||||
//
|
||||
// Literals
|
||||
//
|
||||
|
||||
// strings: escape single quote ' by repeating it '' (SQL style)
|
||||
StringLiteral
|
||||
: '\'' (~'\'')* '\'' ( '\'' (~'\'')* '\'' )*
|
||||
;
|
||||
|
||||
// integer literals
|
||||
IntegerLiteral
|
||||
: Digit+
|
||||
;
|
||||
|
||||
//
|
||||
// miscellaneous syntactic elements
|
||||
//
|
||||
WS
|
||||
: (' '|'\r'|'\t'|'\n') {skip();} // whitepace
|
||||
;
|
||||
|
||||
COMMENT
|
||||
: '--' (~('\n'|'\r'))* { $channel=HIDDEN; }
|
||||
| '/*' (options {greedy=false;} : .)* '*/' { $channel=HIDDEN; }
|
||||
;
|
||||
|
||||
ASSOC: '=>';
|
||||
COMMA: ',';
|
||||
LEFT_BRACE: '{';
|
||||
RIGHT_BRACE: '}';
|
||||
SEMICOLON: ';';
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.compiler.parse;
|
||||
|
||||
import org.antlr.runtime.*;
|
||||
|
||||
public class ParseError {
|
||||
private BaseRecognizer br;
|
||||
private RecognitionException re;
|
||||
private String[] tokenNames;
|
||||
|
||||
public ParseError(BaseRecognizer br, RecognitionException re, String[] tokenNames) {
|
||||
this.br = br;
|
||||
this.re = re;
|
||||
this.tokenNames = tokenNames;
|
||||
}
|
||||
|
||||
public BaseRecognizer getBaseRecognizer() {
|
||||
return br;
|
||||
}
|
||||
|
||||
public RecognitionException getRecognitionException() {
|
||||
return re;
|
||||
}
|
||||
|
||||
public String[] getTokenNames() {
|
||||
return tokenNames;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return br.getErrorHeader(re) + " " + br.getErrorMessage(re, tokenNames);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.compiler.parse;
|
||||
|
||||
/**
|
||||
* Exception from the CQL Parser
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ParseException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
ArrayList<ParseError> errors = null;
|
||||
|
||||
public ParseException(ArrayList<ParseError> errors)
|
||||
{
|
||||
super();
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public ParseException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
|
||||
if (errors == null)
|
||||
return super.getMessage();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(ParseError err: errors) {
|
||||
sb.append(err.getMessage());
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.compiler.sem;
|
||||
|
||||
|
||||
/**
|
||||
* Exception from the CQL SemanticAnalyzer
|
||||
*/
|
||||
|
||||
public class SemanticException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SemanticException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public SemanticException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SemanticException(Throwable cause)
|
||||
{
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public SemanticException(String message, Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,343 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.compiler.sem;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.antlr.runtime.tree.CommonTree;
|
||||
|
||||
import org.apache.cassandra.cql.common.*;
|
||||
import org.apache.cassandra.cql.compiler.common.*;
|
||||
import org.apache.cassandra.cql.compiler.parse.*;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.cql.common.ColumnMapExpr;
|
||||
import org.apache.cassandra.cql.common.ColumnRangeQueryRSD;
|
||||
import org.apache.cassandra.cql.common.ConstantOperand;
|
||||
import org.apache.cassandra.cql.common.ExplainPlan;
|
||||
import org.apache.cassandra.cql.common.OperandDef;
|
||||
import org.apache.cassandra.cql.common.Pair;
|
||||
import org.apache.cassandra.cql.common.Plan;
|
||||
import org.apache.cassandra.cql.common.QueryPlan;
|
||||
import org.apache.cassandra.cql.common.RowSourceDef;
|
||||
import org.apache.cassandra.cql.common.SetColumnMap;
|
||||
import org.apache.cassandra.cql.common.SetSuperColumnMap;
|
||||
import org.apache.cassandra.cql.common.SetUniqueKey;
|
||||
import org.apache.cassandra.cql.common.SuperColumnMapExpr;
|
||||
import org.apache.cassandra.cql.common.SuperColumnRangeQueryRSD;
|
||||
import org.apache.cassandra.cql.common.UniqueKeyQueryRSD;
|
||||
import org.apache.cassandra.cql.common.Utils;
|
||||
import org.apache.cassandra.cql.compiler.common.CompilerErrorMsg;
|
||||
import org.apache.cassandra.cql.compiler.parse.CqlParser;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
//
|
||||
// Note: This class is CQL related work in progress.
|
||||
//
|
||||
// Currently, this phase combines both semantic analysis and code-gen.
|
||||
// I expect that as my ideas get refined/cleared up, I'll be drawing
|
||||
// a more clear distinction between semantic analysis phase and code-gen.
|
||||
//
|
||||
public class SemanticPhase
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(SemanticPhase.class);
|
||||
|
||||
// Current code-gen also happens in this phase!
|
||||
public static Plan doSemanticAnalysis(CommonTree ast) throws SemanticException
|
||||
{
|
||||
Plan plan = null;
|
||||
|
||||
if (logger_.isDebugEnabled())
|
||||
logger_.debug("AST: " + ast.toStringTree());
|
||||
|
||||
switch (ast.getType())
|
||||
{
|
||||
case CqlParser.A_GET:
|
||||
plan = compileGet(ast);
|
||||
break;
|
||||
case CqlParser.A_SET:
|
||||
plan = compileSet(ast);
|
||||
break;
|
||||
case CqlParser.A_DELETE:
|
||||
compileDelete(ast);
|
||||
break;
|
||||
case CqlParser.A_SELECT:
|
||||
compileSelect(ast);
|
||||
break;
|
||||
case CqlParser.A_EXPLAIN_PLAN:
|
||||
// Case: EXPLAN PLAN <stmt>
|
||||
// first, generate a plan for <stmt>
|
||||
// and then, wrapper it with a special ExplainPlan plan
|
||||
// whose execution will result in an explain plan rather
|
||||
// than a normal execution of the statement.
|
||||
plan = doSemanticAnalysis((CommonTree)(ast.getChild(0)));
|
||||
plan = new ExplainPlan(plan);
|
||||
break;
|
||||
default:
|
||||
// Unhandled AST node. Raise an internal error.
|
||||
throw new SemanticException(CompilerErrorMsg.INTERNAL_ERROR.getMsg(ast, "Unknown Node Type: " + ast.getType()));
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a CommonTree AST node of type, A_COLUMN_ACCESS related functions, do semantic
|
||||
* checking to ensure table name, column family name, and number of key dimensions
|
||||
* specified are all valid.
|
||||
*/
|
||||
private static CFMetaData getColumnFamilyInfo(CommonTree ast) throws SemanticException
|
||||
{
|
||||
assert(ast.getType() == CqlParser.A_COLUMN_ACCESS);
|
||||
|
||||
CommonTree columnFamilyNode = (CommonTree)(ast.getChild(1));
|
||||
CommonTree tableNode = (CommonTree)(ast.getChild(0));
|
||||
|
||||
String columnFamily = columnFamilyNode.getText();
|
||||
String table = tableNode.getText();
|
||||
|
||||
Map<String, CFMetaData> columnFamilies = DatabaseDescriptor.getTableMetaData(table);
|
||||
if (columnFamilies == null)
|
||||
{
|
||||
throw new SemanticException(CompilerErrorMsg.INVALID_TABLE.getMsg(ast, table));
|
||||
}
|
||||
|
||||
CFMetaData cfMetaData = columnFamilies.get(columnFamily);
|
||||
if (cfMetaData == null)
|
||||
{
|
||||
throw new SemanticException(CompilerErrorMsg.INVALID_COLUMN_FAMILY.getMsg(ast, columnFamily, table));
|
||||
}
|
||||
|
||||
// Once you have drilled down to a row using a rowKey, a super column
|
||||
// map can be indexed only 2 further levels deep; and a column map may
|
||||
// be indexed up to 1 level deep.
|
||||
int dimensions = numColumnDimensions(ast);
|
||||
if (("Super".equals(cfMetaData.columnType) && (dimensions > 2)) ||
|
||||
("Standard".equals(cfMetaData.columnType) && dimensions > 1))
|
||||
{
|
||||
throw new SemanticException(CompilerErrorMsg.TOO_MANY_DIMENSIONS.getMsg(ast, cfMetaData.columnType));
|
||||
}
|
||||
|
||||
return cfMetaData;
|
||||
}
|
||||
|
||||
private static String getRowKey(CommonTree ast)
|
||||
{
|
||||
assert(ast.getType() == CqlParser.A_COLUMN_ACCESS);
|
||||
return Utils.unescapeSQLString(ast.getChild(2).getText());
|
||||
}
|
||||
|
||||
private static int numColumnDimensions(CommonTree ast)
|
||||
{
|
||||
// Skip over table name, column family and rowKey
|
||||
return ast.getChildCount() - 3;
|
||||
}
|
||||
|
||||
// Returns the pos'th (0-based index) column specifier in the astNode
|
||||
private static String getColumn(CommonTree ast, int pos)
|
||||
{
|
||||
// Skip over table name, column family and rowKey
|
||||
return Utils.unescapeSQLString(ast.getChild(pos + 3).getText());
|
||||
}
|
||||
|
||||
// Compile a GET statement
|
||||
private static Plan compileGet(CommonTree ast) throws SemanticException
|
||||
{
|
||||
int childCount = ast.getChildCount();
|
||||
assert(childCount == 1);
|
||||
|
||||
CommonTree columnFamilySpec = (CommonTree)ast.getChild(0);
|
||||
assert(columnFamilySpec.getType() == CqlParser.A_COLUMN_ACCESS);
|
||||
|
||||
CFMetaData cfMetaData = getColumnFamilyInfo(columnFamilySpec);
|
||||
ConstantOperand rowKey = new ConstantOperand(getRowKey(columnFamilySpec));
|
||||
int dimensionCnt = numColumnDimensions(columnFamilySpec);
|
||||
|
||||
RowSourceDef rwsDef;
|
||||
if ("Super".equals(cfMetaData.columnType))
|
||||
{
|
||||
if (dimensionCnt > 2)
|
||||
{
|
||||
// We don't expect this case to arise, since Cql.g grammar disallows this.
|
||||
// therefore, raise this case as an "internal error".
|
||||
throw new SemanticException(CompilerErrorMsg.INTERNAL_ERROR.getMsg(columnFamilySpec));
|
||||
}
|
||||
|
||||
if (dimensionCnt == 2)
|
||||
{
|
||||
// Case: table.super_cf[<rowKey>][<superColumnKey>][<columnKey>]
|
||||
ConstantOperand superColumnKey = new ConstantOperand(getColumn(columnFamilySpec, 0));
|
||||
ConstantOperand columnKey = new ConstantOperand(getColumn(columnFamilySpec, 1));
|
||||
rwsDef = new UniqueKeyQueryRSD(cfMetaData, rowKey, superColumnKey, columnKey);
|
||||
}
|
||||
else if (dimensionCnt == 1)
|
||||
{
|
||||
// Case: table.super_cf[<rowKey>][<superColumnKey>]
|
||||
ConstantOperand superColumnKey = new ConstantOperand(getColumn(columnFamilySpec, 0));
|
||||
rwsDef = new ColumnRangeQueryRSD(cfMetaData, rowKey, superColumnKey, Integer.MAX_VALUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Case: table.super_cf[<rowKey>]
|
||||
rwsDef = new SuperColumnRangeQueryRSD(cfMetaData, rowKey, Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
else // Standard Column Family
|
||||
{
|
||||
if (dimensionCnt == 1)
|
||||
{
|
||||
// Case: table.standard_cf[<rowKey>][<columnKey>]
|
||||
ConstantOperand columnKey = new ConstantOperand(getColumn(columnFamilySpec, 0));
|
||||
rwsDef = new UniqueKeyQueryRSD(cfMetaData, rowKey, columnKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Case: table.standard_cf[<rowKey>]
|
||||
logger_.assertLog((dimensionCnt == 0), "invalid dimensionCnt: " + dimensionCnt);
|
||||
rwsDef = new ColumnRangeQueryRSD(cfMetaData, rowKey, Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
return new QueryPlan(rwsDef);
|
||||
}
|
||||
|
||||
private static OperandDef getSimpleExpr(CommonTree ast) throws SemanticException
|
||||
{
|
||||
int type = ast.getType();
|
||||
|
||||
// for now, the only simple expressions support are of string type
|
||||
if (type != CqlParser.StringLiteral)
|
||||
{
|
||||
throw new SemanticException(CompilerErrorMsg.INVALID_TYPE.getMsg(ast));
|
||||
}
|
||||
return new ConstantOperand(Utils.unescapeSQLString(ast.getText()));
|
||||
}
|
||||
|
||||
private static ColumnMapExpr getColumnMapExpr(CommonTree ast) throws SemanticException
|
||||
{
|
||||
int type = ast.getType();
|
||||
if (type != CqlParser.A_COLUMN_MAP_VALUE)
|
||||
{
|
||||
throw new SemanticException(CompilerErrorMsg.INVALID_TYPE.getMsg(ast));
|
||||
}
|
||||
|
||||
int size = ast.getChildCount();
|
||||
ColumnMapExpr result = new ColumnMapExpr();
|
||||
for (int idx = 0; idx < size; idx++)
|
||||
{
|
||||
CommonTree entryNode = (CommonTree)(ast.getChild(idx));
|
||||
OperandDef columnKey = getSimpleExpr((CommonTree)(entryNode.getChild(0)));
|
||||
OperandDef columnValue = getSimpleExpr((CommonTree)(entryNode.getChild(1)));
|
||||
|
||||
Pair<OperandDef, OperandDef> entry = new Pair<OperandDef, OperandDef>(columnKey, columnValue);
|
||||
result.add(entry);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static SuperColumnMapExpr getSuperColumnMapExpr(CommonTree ast) throws SemanticException
|
||||
{
|
||||
int type = ast.getType();
|
||||
if (type != CqlParser.A_SUPERCOLUMN_MAP_VALUE)
|
||||
{
|
||||
throw new SemanticException(CompilerErrorMsg.INVALID_TYPE.getMsg(ast));
|
||||
}
|
||||
int size = ast.getChildCount();
|
||||
SuperColumnMapExpr result = new SuperColumnMapExpr();
|
||||
for (int idx = 0; idx < size; idx++)
|
||||
{
|
||||
CommonTree entryNode = (CommonTree)(ast.getChild(idx));
|
||||
OperandDef superColumnKey = getSimpleExpr((CommonTree)(entryNode.getChild(0)));
|
||||
ColumnMapExpr columnMapExpr = getColumnMapExpr((CommonTree)(entryNode.getChild(1)));
|
||||
|
||||
Pair<OperandDef, ColumnMapExpr> entry = new Pair<OperandDef, ColumnMapExpr>(superColumnKey, columnMapExpr);
|
||||
result.add(entry);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// compile a SET statement
|
||||
private static Plan compileSet(CommonTree ast) throws SemanticException
|
||||
{
|
||||
int childCount = ast.getChildCount();
|
||||
assert(childCount == 2);
|
||||
|
||||
CommonTree columnFamilySpec = (CommonTree)ast.getChild(0);
|
||||
assert(columnFamilySpec.getType() == CqlParser.A_COLUMN_ACCESS);
|
||||
|
||||
CFMetaData cfMetaData = getColumnFamilyInfo(columnFamilySpec);
|
||||
ConstantOperand rowKey = new ConstantOperand(getRowKey(columnFamilySpec));
|
||||
int dimensionCnt = numColumnDimensions(columnFamilySpec);
|
||||
|
||||
CommonTree valueNode = (CommonTree)(ast.getChild(1));
|
||||
|
||||
Plan plan = null;
|
||||
if ("Super".equals(cfMetaData.columnType))
|
||||
{
|
||||
if (dimensionCnt == 2)
|
||||
{
|
||||
// Case: set table.super_cf['key']['supercolumn']['column'] = 'value'
|
||||
OperandDef value = getSimpleExpr(valueNode);
|
||||
ConstantOperand superColumnKey = new ConstantOperand(getColumn(columnFamilySpec, 0));
|
||||
ConstantOperand columnKey = new ConstantOperand(getColumn(columnFamilySpec, 1));
|
||||
plan = new SetUniqueKey(cfMetaData, rowKey, superColumnKey, columnKey, value);
|
||||
}
|
||||
else if (dimensionCnt == 1)
|
||||
{
|
||||
// Case: set table.super_cf['key']['supercolumn'] = <column_map>;
|
||||
ColumnMapExpr columnMapExpr = getColumnMapExpr(valueNode);
|
||||
ConstantOperand superColumnKey = new ConstantOperand(getColumn(columnFamilySpec, 0));
|
||||
plan = new SetColumnMap(cfMetaData, rowKey, superColumnKey, columnMapExpr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Case: set table.super_cf['key'] = <super_column_map>;
|
||||
logger_.assertLog(dimensionCnt == 0, "invalid dimensionCnt: " + dimensionCnt);
|
||||
SuperColumnMapExpr superColumnMapExpr = getSuperColumnMapExpr(valueNode);
|
||||
plan = new SetSuperColumnMap(cfMetaData, rowKey, superColumnMapExpr);
|
||||
}
|
||||
}
|
||||
else // Standard column family
|
||||
{
|
||||
if (dimensionCnt == 1)
|
||||
{
|
||||
// Case: set table.standard_cf['key']['column'] = 'value'
|
||||
OperandDef value = getSimpleExpr(valueNode);
|
||||
ConstantOperand columnKey = new ConstantOperand(getColumn(columnFamilySpec, 0));
|
||||
plan = new SetUniqueKey(cfMetaData, rowKey, columnKey, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Case: set table.standard_cf['key'] = <column_map>;
|
||||
logger_.assertLog(dimensionCnt == 0, "invalid dimensionCnt: " + dimensionCnt);
|
||||
ColumnMapExpr columnMapExpr = getColumnMapExpr(valueNode);
|
||||
plan = new SetColumnMap(cfMetaData, rowKey, columnMapExpr);
|
||||
}
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
|
||||
private static void compileSelect(CommonTree ast) throws SemanticException
|
||||
{
|
||||
// stub; tbd.
|
||||
}
|
||||
private static void compileDelete(CommonTree ast) throws SemanticException
|
||||
{
|
||||
// stub; tbd.
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.driver;
|
||||
|
||||
import org.apache.cassandra.cql.common.CqlResult;
|
||||
import org.apache.cassandra.cql.common.Plan;
|
||||
import org.apache.cassandra.cql.compiler.common.CqlCompiler;
|
||||
import org.apache.cassandra.cql.compiler.parse.ParseException;
|
||||
import org.apache.cassandra.cql.compiler.sem.SemanticException;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
// Server side driver class for CQL
|
||||
public class CqlDriver
|
||||
{
|
||||
private final static Logger logger_ = Logger.getLogger(CqlDriver.class);
|
||||
|
||||
// Execute a CQL Statement
|
||||
public static CqlResult executeQuery(String query)
|
||||
{
|
||||
CqlCompiler compiler = new CqlCompiler();
|
||||
|
||||
try
|
||||
{
|
||||
if (logger_.isDebugEnabled())
|
||||
logger_.debug("Compiling CQL query ...");
|
||||
Plan plan = compiler.compileQuery(query);
|
||||
if (plan != null)
|
||||
{
|
||||
if (logger_.isDebugEnabled())
|
||||
logger_.debug("Executing CQL query ...");
|
||||
return plan.execute();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CqlResult result = new CqlResult(null);
|
||||
result.errorTxt = e.getMessage();
|
||||
|
||||
Class<? extends Exception> excpClass = e.getClass();
|
||||
if ((excpClass != SemanticException.class)
|
||||
&& (excpClass != ParseException.class)
|
||||
&& (excpClass != RuntimeException.class))
|
||||
{
|
||||
result.errorTxt = "CQL Internal Error: " + result.errorTxt;
|
||||
result.errorCode = 1; // failure
|
||||
logger_.error(LogUtil.throwableToString(e));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.cassandra.cql.execution;
|
||||
|
||||
/**
|
||||
* List of error messages thrown by CQL's Execution Layer
|
||||
**/
|
||||
public enum RuntimeErrorMsg
|
||||
{
|
||||
// Error messages with String.format() style format specifiers
|
||||
GENERIC_ERROR("CQL Execution Error"),
|
||||
INTERNAL_ERROR("CQL Internal Error: %s"),
|
||||
IMPLEMENTATION_RESTRICTION("Implementation Restriction: %s"),
|
||||
NO_DATA_FOUND("No data found")
|
||||
;
|
||||
|
||||
private String mesg;
|
||||
RuntimeErrorMsg(String mesg)
|
||||
{
|
||||
this.mesg = mesg;
|
||||
}
|
||||
|
||||
// Returns the formatted error message.
|
||||
public String getMsg(Object... args)
|
||||
{
|
||||
// note: mesg itself might contain other format specifiers...
|
||||
return String.format(mesg, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -30,8 +30,6 @@ import org.apache.commons.lang.ArrayUtils;
|
|||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.cql.common.CqlResult;
|
||||
import org.apache.cassandra.cql.driver.CqlDriver;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.marshal.MarshalException;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
|
|
@ -471,22 +469,6 @@ public class CassandraServer implements Cassandra.Iface
|
|||
return columnFamiliesMap;
|
||||
}
|
||||
|
||||
public org.apache.cassandra.service.CqlResult execute_query(String query) throws TException
|
||||
{
|
||||
org.apache.cassandra.service.CqlResult result = new org.apache.cassandra.service.CqlResult();
|
||||
|
||||
CqlResult cqlResult = CqlDriver.executeQuery(query);
|
||||
|
||||
// convert CQL result type to Thrift specific return type
|
||||
if (cqlResult != null)
|
||||
{
|
||||
result.error_txt = cqlResult.errorTxt;
|
||||
result.result_set = cqlResult.resultSet;
|
||||
result.error_code = cqlResult.errorCode;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<String> get_key_range(String tablename, String columnFamily, String startWith, String stopAt, int maxResults) throws InvalidRequestException, TException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
|
|
|
|||
Loading…
Reference in New Issue