Skip to content

Commit

Permalink
CQL3 refactor to allow conversion function
Browse files Browse the repository at this point in the history
patch by slebresne; reviewed by iamaleksey for CASSANDRA-5226
  • Loading branch information
Sylvain Lebresne committed Feb 8, 2013
1 parent 1423fb1 commit 31e669a
Show file tree
Hide file tree
Showing 59 changed files with 3,560 additions and 2,516 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -13,6 +13,7 @@
* Expose secondary indicies to the rest of nodetool (CASSANDRA-4464)
* Binary protocol: avoid sending notification for 0.0.0.0 (CASSANDRA-5227)
* add UseCondCardMark XX jvm settings on jdk 1.7 (CASSANDRA-4366)
* CQL3 refactor to allow conversion function (CASSANDRA-5226)


1.2.1
Expand Down
149 changes: 95 additions & 54 deletions doc/cql3/CQL.textile

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions src/java/org/apache/cassandra/cql3/AbstractMarker.java
@@ -0,0 +1,82 @@
/*
* 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.cql3;

import java.nio.ByteBuffer;

import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.exceptions.InvalidRequestException;


/**
* A single bind marker.
*/
public abstract class AbstractMarker extends Term.NonTerminal
{
protected final int bindIndex;
protected final ColumnSpecification receiver;

protected AbstractMarker(int bindIndex, ColumnSpecification receiver)
{
this.bindIndex = bindIndex;
this.receiver = receiver;
}

public void collectMarkerSpecification(ColumnSpecification[] boundNames)
{
boundNames[bindIndex] = receiver;
}

/**
* A parsed, but non prepared, bind marker.
*/
public static class Raw implements Term.Raw
{
protected final int bindIndex;

public Raw(int bindIndex)
{
this.bindIndex = bindIndex;
}

public AbstractMarker prepare(ColumnSpecification receiver) throws InvalidRequestException
{
if (!(receiver.type instanceof CollectionType))
return new Constants.Marker(bindIndex, receiver);

switch (((CollectionType)receiver.type).kind)
{
case LIST: return new Lists.Marker(bindIndex, receiver);
case SET: return new Sets.Marker(bindIndex, receiver);
case MAP: return new Maps.Marker(bindIndex, receiver);
}
throw new AssertionError();
}

public boolean isAssignableTo(ColumnSpecification receiver)
{
return true;
}

@Override
public String toString()
{
return "?";
}
}
}
26 changes: 26 additions & 0 deletions src/java/org/apache/cassandra/cql3/AssignementTestable.java
@@ -0,0 +1,26 @@
/*
* 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.cql3;

public interface AssignementTestable
{
/**
* @return whether this object can be assigned to the provided receiver
*/
public boolean isAssignableTo(ColumnSpecification receiver);
}
30 changes: 23 additions & 7 deletions src/java/org/apache/cassandra/cql3/CFDefinition.java
Expand Up @@ -21,6 +21,7 @@
import java.util.*;

import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.collect.AbstractIterator;

import org.apache.cassandra.config.CFMetaData;
Expand Down Expand Up @@ -293,6 +294,26 @@ private Name(String ksName, String cfName, ColumnIdentifier name, Kind kind, int

public final Kind kind;
public final int position; // only make sense for KEY_ALIAS and COLUMN_ALIAS

@Override
public boolean equals(Object o)
{
if(!(o instanceof Name))
return false;
Name that = (Name)o;
return Objects.equal(ksName, that.ksName)
&& Objects.equal(cfName, that.cfName)
&& Objects.equal(name, that.name)
&& Objects.equal(type, that.type)
&& kind == that.kind
&& position == that.position;
}

@Override
public final int hashCode()
{
return Objects.hashCode(ksName, cfName, name, type, kind, position);
}
}

@Override
Expand Down Expand Up @@ -329,14 +350,9 @@ public NonCompositeBuilder add(ByteBuffer bb)
return this;
}

public NonCompositeBuilder add(Term t, Relation.Type op, List<ByteBuffer> variables) throws InvalidRequestException
public NonCompositeBuilder add(ByteBuffer bb, Relation.Type op)
{
if (columnName != null)
throw new IllegalStateException("Column name is already constructed");

// We don't support the relation type yet, i.e., there is no distinction between x > 3 and x >= 3.
columnName = t.getByteBuffer(type, variables);
return this;
return add(bb);
}

public int componentCount()
Expand Down
9 changes: 2 additions & 7 deletions src/java/org/apache/cassandra/cql3/ColumnIdentifier.java
Expand Up @@ -23,12 +23,12 @@
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.utils.ByteBufferUtil;

import org.apache.cassandra.cql3.statements.Selector;
import org.apache.cassandra.cql3.statements.RawSelector;

/**
* Represents an identifer for a CQL column definition.
*/
public class ColumnIdentifier extends Selector implements Comparable<ColumnIdentifier>
public class ColumnIdentifier implements RawSelector, Comparable<ColumnIdentifier>
{
public final ByteBuffer key;
private final String text;
Expand Down Expand Up @@ -70,9 +70,4 @@ public int compareTo(ColumnIdentifier other)
{
return key.compareTo(other.key);
}

public ColumnIdentifier id()
{
return this;
}
}
7 changes: 3 additions & 4 deletions src/java/org/apache/cassandra/cql3/ColumnNameBuilder.java
Expand Up @@ -36,14 +36,13 @@ public interface ColumnNameBuilder
public ColumnNameBuilder add(ByteBuffer bb);

/**
* Add a new Term as the next component for this name.
* @param t the Term to add
* Add a new ByteBuffer as the next component for this name.
* @param bb the ByteBuffer to add
* @param op the relationship this component should respect.
* @param variables the variables corresponding to prepared markers
* @throws IllegalStateException if the builder if full, i.e. if enough component has been added.
* @return this builder
*/
public ColumnNameBuilder add(Term t, Relation.Type op, List<ByteBuffer> variables) throws InvalidRequestException;
public ColumnNameBuilder add(ByteBuffer t, Relation.Type op);

/**
* Returns the number of component already added to this builder.
Expand Down

0 comments on commit 31e669a

Please sign in to comment.