You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sn...@apache.org on 2015/11/06 18:29:50 UTC
[2/3] cassandra git commit: Store UDA initcond as CQL literal in the
schema table, instead of a blob
Store UDA initcond as CQL literal in the schema table, instead of a blob
patch by Robert Stupp; reviewed by Aleksey Yeschenko for CASSANDRA-10650
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e94032a2
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e94032a2
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e94032a2
Branch: refs/heads/trunk
Commit: e94032a2346ac07b4d2c0d2e4de6d88b16da05d2
Parents: cfbe2d3
Author: Robert Stupp <sn...@snazy.de>
Authored: Fri Nov 6 18:26:00 2015 +0100
Committer: Robert Stupp <sn...@snazy.de>
Committed: Fri Nov 6 18:28:48 2015 +0100
----------------------------------------------------------------------
CHANGES.txt | 1 +
...core-3.0.0-beta1-92c4c80-SNAPSHOT-shaded.jar | Bin 2284484 -> 0 bytes
...core-3.0.0-beta1-bb1bce4-SNAPSHOT-shaded.jar | Bin 0 -> 2288891 bytes
lib/licenses/cassandra-driver-2.1.3.txt | 177 -----
lib/licenses/cassandra-driver-3.0.0.txt | 177 +++++
.../apache/cassandra/config/ViewDefinition.java | 15 +-
.../org/apache/cassandra/cql3/CQL3Type.java | 223 +++++-
.../cassandra/cql3/CQLFragmentParser.java | 84 ++
.../apache/cassandra/cql3/ColumnIdentifier.java | 10 +-
.../apache/cassandra/cql3/QueryProcessor.java | 19 +-
src/java/org/apache/cassandra/cql3/Terms.java | 9 +
.../statements/CreateAggregateStatement.java | 3 +-
.../cassandra/db/marshal/AbstractType.java | 2 +-
.../apache/cassandra/schema/CQLTypeParser.java | 35 +-
.../apache/cassandra/schema/SchemaKeyspace.java | 10 +-
.../serializers/AbstractTextSerializer.java | 28 +
.../cassandra/serializers/BytesSerializer.java | 14 +
.../serializers/TimestampSerializer.java | 32 +-
.../cassandra/serializers/TypeSerializer.java | 8 +
.../cassandra/cql3/CQL3TypeLiteralTest.java | 786 +++++++++++++++++++
.../validation/operations/AggregationTest.java | 15 +
.../schema/LegacySchemaMigratorTest.java | 6 +-
22 files changed, 1390 insertions(+), 264 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index c39f119..9966bfd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
3.0
+ * Store UDA initcond as CQL literal in the schema table, instead of a blob (CASSANDRA-10650)
* Don't use -1 for the position of partition key in schema (CASSANDRA-10491)
* Fix distinct queries in mixed version cluster (CASSANDRA-10573)
* Skip sstable on clustering in names query (CASSANDRA-10571)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/lib/cassandra-driver-core-3.0.0-beta1-92c4c80-SNAPSHOT-shaded.jar
----------------------------------------------------------------------
diff --git a/lib/cassandra-driver-core-3.0.0-beta1-92c4c80-SNAPSHOT-shaded.jar b/lib/cassandra-driver-core-3.0.0-beta1-92c4c80-SNAPSHOT-shaded.jar
deleted file mode 100644
index 2026c52..0000000
Binary files a/lib/cassandra-driver-core-3.0.0-beta1-92c4c80-SNAPSHOT-shaded.jar and /dev/null differ
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/lib/cassandra-driver-core-3.0.0-beta1-bb1bce4-SNAPSHOT-shaded.jar
----------------------------------------------------------------------
diff --git a/lib/cassandra-driver-core-3.0.0-beta1-bb1bce4-SNAPSHOT-shaded.jar b/lib/cassandra-driver-core-3.0.0-beta1-bb1bce4-SNAPSHOT-shaded.jar
new file mode 100644
index 0000000..b8f002f
Binary files /dev/null and b/lib/cassandra-driver-core-3.0.0-beta1-bb1bce4-SNAPSHOT-shaded.jar differ
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/lib/licenses/cassandra-driver-2.1.3.txt
----------------------------------------------------------------------
diff --git a/lib/licenses/cassandra-driver-2.1.3.txt b/lib/licenses/cassandra-driver-2.1.3.txt
deleted file mode 100644
index f433b1a..0000000
--- a/lib/licenses/cassandra-driver-2.1.3.txt
+++ /dev/null
@@ -1,177 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/lib/licenses/cassandra-driver-3.0.0.txt
----------------------------------------------------------------------
diff --git a/lib/licenses/cassandra-driver-3.0.0.txt b/lib/licenses/cassandra-driver-3.0.0.txt
new file mode 100644
index 0000000..f433b1a
--- /dev/null
+++ b/lib/licenses/cassandra-driver-3.0.0.txt
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/config/ViewDefinition.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/ViewDefinition.java b/src/java/org/apache/cassandra/config/ViewDefinition.java
index 02acc68..b29a8f9 100644
--- a/src/java/org/apache/cassandra/config/ViewDefinition.java
+++ b/src/java/org/apache/cassandra/config/ViewDefinition.java
@@ -151,22 +151,9 @@ public class ViewDefinition
private static List<Relation> whereClauseToRelations(String whereClause)
{
- ErrorCollector errorCollector = new ErrorCollector(whereClause);
- CharStream stream = new ANTLRStringStream(whereClause);
- CqlLexer lexer = new CqlLexer(stream);
- lexer.addErrorListener(errorCollector);
-
- TokenStream tokenStream = new CommonTokenStream(lexer);
- CqlParser parser = new CqlParser(tokenStream);
- parser.addErrorListener(errorCollector);
-
try
{
- List<Relation> relations = parser.whereClause().build().relations;
-
- // The errorCollector has queued up any errors that the lexer and parser may have encountered
- // along the way, if necessary, we turn the last error into exceptions here.
- errorCollector.throwFirstSyntaxError();
+ List<Relation> relations = CQLFragmentParser.parseAnyUnhandled(CqlParser::whereClause, whereClause).build().relations;
return relations;
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/cql3/CQL3Type.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/CQL3Type.java b/src/java/org/apache/cassandra/cql3/CQL3Type.java
index fde3fab..0c4ef17 100644
--- a/src/java/org/apache/cassandra/cql3/CQL3Type.java
+++ b/src/java/org/apache/cassandra/cql3/CQL3Type.java
@@ -17,6 +17,7 @@
*/
package org.apache.cassandra.cql3;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +31,9 @@ import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.schema.KeyspaceMetadata;
import org.apache.cassandra.schema.Types;
+import org.apache.cassandra.serializers.CollectionSerializer;
+import org.apache.cassandra.serializers.MarshalException;
+import org.apache.cassandra.utils.ByteBufferUtil;
public interface CQL3Type
{
@@ -38,6 +42,23 @@ public interface CQL3Type
public boolean isCollection();
public AbstractType<?> getType();
+ /**
+ * Generate CQL literal from this type's serialized representation using the specified protocol version.
+ * Convinience method for {@link #toCQLLiteral(ByteBuffer, int, StringBuilder)} that just returns a {@code String}.
+ */
+ public default String asCQLLiteral(ByteBuffer buffer, int version)
+ {
+ StringBuilder sb = new StringBuilder();
+ toCQLLiteral(buffer, version, sb);
+ return sb.toString();
+ }
+
+ /**
+ * Generate CQL literal from this type's serialized representation using the specified protocol version.
+ * Some work is delegated to {@link org.apache.cassandra.serializers.TypeSerializer#toCQLLiteral(ByteBuffer, StringBuilder)}.
+ */
+ public void toCQLLiteral(ByteBuffer buffer, int version, StringBuilder target);
+
public enum Native implements CQL3Type
{
ASCII (AsciiType.instance),
@@ -79,6 +100,18 @@ public interface CQL3Type
return type;
}
+ /**
+ * Delegate to
+ * {@link org.apache.cassandra.serializers.TypeSerializer#toCQLLiteral(ByteBuffer, StringBuilder)}
+ * for native types as most CQL literal representations work fine with the default
+ * {@link org.apache.cassandra.serializers.TypeSerializer#toString(Object)}
+ * {@link org.apache.cassandra.serializers.TypeSerializer#deserialize(ByteBuffer)} implementations.
+ */
+ public void toCQLLiteral(ByteBuffer buffer, int version, StringBuilder target)
+ {
+ type.getSerializer().toCQLLiteral(buffer, target);
+ }
+
@Override
public String toString()
{
@@ -110,6 +143,14 @@ public interface CQL3Type
return type;
}
+ public void toCQLLiteral(ByteBuffer buffer, int version, StringBuilder target)
+ {
+ if (buffer == null)
+ target.append("null");
+ else
+ target.append(type.getString(buffer));
+ }
+
@Override
public final boolean equals(Object o)
{
@@ -129,7 +170,7 @@ public interface CQL3Type
@Override
public String toString()
{
- return "'" + type + "'";
+ return "'" + type + '\'';
}
}
@@ -152,6 +193,88 @@ public interface CQL3Type
return true;
}
+ public void toCQLLiteral(ByteBuffer buffer, int version, StringBuilder target)
+ {
+ // Not sure whether the !buffer.hasRemaining() check is correct here or whether an empty
+ // BB should be returned as "[]" resp "{}" or whether it is not valid at all.
+ //
+ // Currently, all empty collections return '[]' or '{}'. Except frozen collections with
+ // a null BB return 'null'.
+ //
+ if (buffer == null || !buffer.hasRemaining())
+ {
+ if (buffer == null && type.isFrozenCollection())
+ {
+ target.append("null");
+ }
+ else
+ {
+ switch (type.kind)
+ {
+ case LIST:
+ target.append("[]");
+ break;
+ case SET:
+ case MAP:
+ target.append("{}");
+ break;
+ }
+ }
+ }
+ else
+ {
+ int size = CollectionSerializer.readCollectionSize(buffer, version);
+
+ switch (type.kind)
+ {
+ case LIST:
+ CQL3Type elements = ((ListType) type).getElementsType().asCQL3Type();
+ target.append('[');
+ generateSetOrListCQLLiteral(buffer, version, target, size, elements);
+ target.append(']');
+ break;
+ case SET:
+ elements = ((SetType) type).getElementsType().asCQL3Type();
+ target.append('{');
+ generateSetOrListCQLLiteral(buffer, version, target, size, elements);
+ target.append('}');
+ break;
+ case MAP:
+ target.append('{');
+ generateMapCQLLiteral(buffer, version, target, size);
+ target.append('}');
+ break;
+ }
+ }
+ }
+
+ private void generateMapCQLLiteral(ByteBuffer buffer, int version, StringBuilder target, int size)
+ {
+ CQL3Type keys = ((MapType) type).getKeysType().asCQL3Type();
+ CQL3Type values = ((MapType) type).getValuesType().asCQL3Type();
+ for (int i = 0; i < size; i++)
+ {
+ if (i > 0)
+ target.append(", ");
+ ByteBuffer element = CollectionSerializer.readValue(buffer, version);
+ keys.toCQLLiteral(element, version, target);
+ target.append(": ");
+ element = CollectionSerializer.readValue(buffer, version);
+ values.toCQLLiteral(element, version, target);
+ }
+ }
+
+ private static void generateSetOrListCQLLiteral(ByteBuffer buffer, int version, StringBuilder target, int size, CQL3Type elements)
+ {
+ for (int i = 0; i < size; i++)
+ {
+ if (i > 0)
+ target.append(", ");
+ ByteBuffer element = CollectionSerializer.readValue(buffer, version);
+ elements.toCQLLiteral(element, version, target);
+ }
+ }
+
@Override
public final boolean equals(Object o)
{
@@ -191,9 +314,9 @@ public interface CQL3Type
default:
throw new AssertionError();
}
- sb.append(">");
+ sb.append('>');
if (isFrozen)
- sb.append(">");
+ sb.append('>');
return sb.toString();
}
}
@@ -225,6 +348,49 @@ public interface CQL3Type
return type;
}
+ public void toCQLLiteral(ByteBuffer buffer, int version, StringBuilder target)
+ {
+ if (buffer == null)
+ {
+ target.append("null");
+ }
+ else
+ {
+ target.append('{');
+ for (int i = 0; i < type.size(); i++)
+ {
+ // we allow the input to have less fields than declared so as to support field addition.
+ if (!buffer.hasRemaining())
+ break;
+
+ if (buffer.remaining() < 4)
+ throw new MarshalException(String.format("Not enough bytes to read size of %dth field %s", i, type.fieldName(i)));
+
+ int size = buffer.getInt();
+
+ if (i > 0)
+ target.append(", ");
+
+ target.append(ColumnIdentifier.maybeQuote(type.fieldNameAsString(i)));
+ target.append(": ");
+
+ // size < 0 means null value
+ if (size < 0)
+ {
+ target.append("null");
+ continue;
+ }
+
+ if (buffer.remaining() < size)
+ throw new MarshalException(String.format("Not enough bytes to read %dth field %s", i, type.fieldName(i)));
+
+ ByteBuffer field = ByteBufferUtil.readBytes(buffer, size);
+ type.fieldType(i).asCQL3Type().toCQLLiteral(field, version, target);
+ }
+ target.append('}');
+ }
+ }
+
@Override
public final boolean equals(Object o)
{
@@ -272,6 +438,49 @@ public interface CQL3Type
return type;
}
+ public void toCQLLiteral(ByteBuffer buffer, int version, StringBuilder target)
+ {
+ if (buffer == null)
+ {
+ target.append("null");
+ }
+ else
+ {
+ target.append('(');
+ boolean first = true;
+ for (int i = 0; i < type.size(); i++)
+ {
+ // we allow the input to have less fields than declared so as to support field addition.
+ if (!buffer.hasRemaining())
+ break;
+
+ if (buffer.remaining() < 4)
+ throw new MarshalException(String.format("Not enough bytes to read size of %dth component", i));
+
+ int size = buffer.getInt();
+
+ if (first)
+ first = false;
+ else
+ target.append(", ");
+
+ // size < 0 means null value
+ if (size < 0)
+ {
+ target.append("null");
+ continue;
+ }
+
+ if (buffer.remaining() < size)
+ throw new MarshalException(String.format("Not enough bytes to read %dth component", i));
+
+ ByteBuffer field = ByteBufferUtil.readBytes(buffer, size);
+ type.type(i).asCQL3Type().toCQLLiteral(field, version, target);
+ }
+ target.append(')');
+ }
+ }
+
@Override
public final boolean equals(Object o)
{
@@ -515,9 +724,9 @@ public interface CQL3Type
String end = frozen ? ">" : "";
switch (kind)
{
- case LIST: return start + "list<" + values + ">" + end;
- case SET: return start + "set<" + values + ">" + end;
- case MAP: return start + "map<" + keys + ", " + values + ">" + end;
+ case LIST: return start + "list<" + values + '>' + end;
+ case SET: return start + "set<" + values + '>' + end;
+ case MAP: return start + "map<" + keys + ", " + values + '>' + end;
}
throw new AssertionError();
}
@@ -650,7 +859,7 @@ public interface CQL3Type
sb.append(", ");
sb.append(types.get(i));
}
- sb.append(">");
+ sb.append('>');
return sb.toString();
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/cql3/CQLFragmentParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/CQLFragmentParser.java b/src/java/org/apache/cassandra/cql3/CQLFragmentParser.java
new file mode 100644
index 0000000..d6f4732
--- /dev/null
+++ b/src/java/org/apache/cassandra/cql3/CQLFragmentParser.java
@@ -0,0 +1,84 @@
+/*
+ * 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 org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.TokenStream;
+import org.apache.cassandra.exceptions.SyntaxException;
+
+/**
+ * Helper class to encapsulate common code that calls one of the generated methods in {@code CqlParser}.
+ */
+public final class CQLFragmentParser
+{
+
+ @FunctionalInterface
+ public interface CQLParserFunction<R>
+ {
+ R parse(CqlParser parser) throws RecognitionException;
+ }
+
+ public static <R> R parseAny(CQLParserFunction<R> parserFunction, String input, String meaning)
+ {
+ try
+ {
+ return parseAnyUnhandled(parserFunction, input);
+ }
+ catch (RuntimeException re)
+ {
+ throw new SyntaxException(String.format("Failed parsing %s: [%s] reason: %s %s",
+ meaning,
+ input,
+ re.getClass().getSimpleName(),
+ re.getMessage()));
+ }
+ catch (RecognitionException e)
+ {
+ throw new SyntaxException("Invalid or malformed " + meaning + ": " + e.getMessage());
+ }
+ }
+
+ /**
+ * Just call a parser method in {@link CqlParser} - does not do any error handling.
+ */
+ public static <R> R parseAnyUnhandled(CQLParserFunction<R> parserFunction, String input) throws RecognitionException
+ {
+ // Lexer and parser
+ ErrorCollector errorCollector = new ErrorCollector(input);
+ CharStream stream = new ANTLRStringStream(input);
+ CqlLexer lexer = new CqlLexer(stream);
+ lexer.addErrorListener(errorCollector);
+
+ TokenStream tokenStream = new CommonTokenStream(lexer);
+ CqlParser parser = new CqlParser(tokenStream);
+ parser.addErrorListener(errorCollector);
+
+ // Parse the query string to a statement instance
+ R r = parserFunction.parse(parser);
+
+ // The errorCollector has queue up any errors that the lexer and parser may have encountered
+ // along the way, if necessary, we turn the last error into exceptions here.
+ errorCollector.throwFirstSyntaxError();
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java b/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java
index 745e4f0..93734e9 100644
--- a/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java
+++ b/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java
@@ -18,11 +18,10 @@
package org.apache.cassandra.cql3;
import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
import java.util.List;
import java.util.Locale;
-import java.nio.ByteBuffer;
import java.util.concurrent.ConcurrentMap;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.collect.MapMaker;
@@ -36,7 +35,6 @@ import org.apache.cassandra.cql3.selection.SimpleSelector;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.db.marshal.UTF8Type;
-import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.ObjectSizes;
import org.apache.cassandra.utils.memory.AbstractAllocator;
@@ -45,8 +43,10 @@ import org.apache.cassandra.utils.memory.AbstractAllocator;
* Represents an identifer for a CQL column definition.
* TODO : should support light-weight mode without text representation for when not interned
*/
-public class ColumnIdentifier extends org.apache.cassandra.cql3.selection.Selectable implements IMeasurableMemory, Comparable<ColumnIdentifier>
+public class ColumnIdentifier extends Selectable implements IMeasurableMemory, Comparable<ColumnIdentifier>
{
+ private static final Pattern PATTERN_DOUBLE_QUOTE = Pattern.compile("\"", Pattern.LITERAL);
+
public final ByteBuffer bytes;
private final String text;
/**
@@ -332,6 +332,6 @@ public class ColumnIdentifier extends org.apache.cassandra.cql3.selection.Select
{
if (UNQUOTED_IDENTIFIER.matcher(text).matches())
return text;
- return "\"" + text.replace("\"", "\"\"") + "\"";
+ return '"' + PATTERN_DOUBLE_QUOTE.matcher(text).replaceAll(Matcher.quoteReplacement("\"\"")) + '"';
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/cql3/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
index 18f63c2..59d4148 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -508,24 +508,7 @@ public class QueryProcessor implements QueryHandler
{
try
{
- // Lexer and parser
- ErrorCollector errorCollector = new ErrorCollector(queryStr);
- CharStream stream = new ANTLRStringStream(queryStr);
- CqlLexer lexer = new CqlLexer(stream);
- lexer.addErrorListener(errorCollector);
-
- TokenStream tokenStream = new CommonTokenStream(lexer);
- CqlParser parser = new CqlParser(tokenStream);
- parser.addErrorListener(errorCollector);
-
- // Parse the query string to a statement instance
- ParsedStatement statement = parser.query();
-
- // The errorCollector has queue up any errors that the lexer and parser may have encountered
- // along the way, if necessary, we turn the last error into exceptions here.
- errorCollector.throwFirstSyntaxError();
-
- return statement;
+ return CQLFragmentParser.parseAnyUnhandled(CqlParser::query, queryStr);
}
catch (CassandraException ce)
{
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/cql3/Terms.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/Terms.java b/src/java/org/apache/cassandra/cql3/Terms.java
index 0b049b9..ae4bc13 100644
--- a/src/java/org/apache/cassandra/cql3/Terms.java
+++ b/src/java/org/apache/cassandra/cql3/Terms.java
@@ -17,11 +17,13 @@
*/
package org.apache.cassandra.cql3;
+import java.nio.ByteBuffer;
import java.util.Collections;
import com.google.common.collect.Iterables;
import org.apache.cassandra.cql3.functions.Function;
+import org.apache.cassandra.db.marshal.AbstractType;
public class Terms
{
@@ -42,4 +44,11 @@ public class Terms
return Iterables.concat(Iterables.transform(terms, TO_FUNCTION_ITERABLE));
}
+
+ public static ByteBuffer asBytes(String keyspace, String term, AbstractType type)
+ {
+ ColumnSpecification receiver = new ColumnSpecification(keyspace, "--dummy--", new ColumnIdentifier("(dummy)", true), type);
+ Term.Raw rawTerm = CQLFragmentParser.parseAny(CqlParser::term, term, "CQL term");
+ return rawTerm.prepare(keyspace, receiver).bindAndGet(QueryOptions.DEFAULT);
+ }
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/cql3/statements/CreateAggregateStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateAggregateStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateAggregateStatement.java
index 98354d5..6fd0334 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateAggregateStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateAggregateStatement.java
@@ -113,8 +113,7 @@ public final class CreateAggregateStatement extends SchemaAlteringStatement
if (ival != null)
{
- ColumnSpecification receiver = new ColumnSpecification(functionName.keyspace, "--dummy--", new ColumnIdentifier("(aggregate_initcond)", true), stateType);
- initcond = ival.prepare(functionName.keyspace, receiver).bindAndGet(QueryOptions.DEFAULT);
+ initcond = Terms.asBytes(functionName.keyspace, ival.toString(), stateType);
if (Constants.NULL_LITERAL != ival && UDHelper.isNullOrEmpty(stateType, initcond))
throw new InvalidRequestException("INITCOND must not be empty for all types except TEXT, ASCII, BLOB");
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/db/marshal/AbstractType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/AbstractType.java b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
index a0d915f..0253ac6 100644
--- a/src/java/org/apache/cassandra/db/marshal/AbstractType.java
+++ b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
@@ -119,7 +119,7 @@ public abstract class AbstractType<T> implements Comparator<ByteBuffer>
return getSerializer().serialize(value);
}
- /** get a string representation of the bytes suitable for log messages */
+ /** get a string representation of the bytes used for various identifier (NOT just for log messages) */
public String getString(ByteBuffer bytes)
{
if (bytes == null)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/schema/CQLTypeParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/CQLTypeParser.java b/src/java/org/apache/cassandra/schema/CQLTypeParser.java
index ed68498..c79de88 100644
--- a/src/java/org/apache/cassandra/schema/CQLTypeParser.java
+++ b/src/java/org/apache/cassandra/schema/CQLTypeParser.java
@@ -19,11 +19,9 @@ package org.apache.cassandra.schema;
import com.google.common.collect.ImmutableSet;
-import org.antlr.runtime.*;
import org.apache.cassandra.cql3.*;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.UserType;
-import org.apache.cassandra.exceptions.SyntaxException;
import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
@@ -57,37 +55,6 @@ public final class CQLTypeParser
static CQL3Type.Raw parseRaw(String type)
{
- try
- {
- // Lexer and parser
- ErrorCollector errorCollector = new ErrorCollector(type);
- CharStream stream = new ANTLRStringStream(type);
- CqlLexer lexer = new CqlLexer(stream);
- lexer.addErrorListener(errorCollector);
-
- TokenStream tokenStream = new CommonTokenStream(lexer);
- CqlParser parser = new CqlParser(tokenStream);
- parser.addErrorListener(errorCollector);
-
- // Parse the query string to a statement instance
- CQL3Type.Raw rawType = parser.comparatorType();
-
- // The errorCollector has queue up any errors that the lexer and parser may have encountered
- // along the way, if necessary, we turn the last error into exceptions here.
- errorCollector.throwFirstSyntaxError();
-
- return rawType;
- }
- catch (RuntimeException re)
- {
- throw new SyntaxException(String.format("Failed parsing statement: [%s] reason: %s %s",
- type,
- re.getClass().getSimpleName(),
- re.getMessage()));
- }
- catch (RecognitionException e)
- {
- throw new SyntaxException("Invalid or malformed CQL type: " + e.getMessage());
- }
+ return CQLFragmentParser.parseAny(CqlParser::comparatorType, type, "CQL type");
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
index c715a2a..f1ea6cf 100644
--- a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
+++ b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
@@ -43,6 +43,7 @@ import org.apache.cassandra.db.rows.*;
import org.apache.cassandra.db.view.View;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.transport.Server;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Pair;
@@ -223,7 +224,7 @@ public final class SchemaKeyspace
+ "aggregate_name text,"
+ "argument_types frozen<list<text>>,"
+ "final_func text,"
- + "initcond blob,"
+ + "initcond text,"
+ "return_type text,"
+ "state_func text,"
+ "state_type text,"
@@ -833,11 +834,12 @@ public final class SchemaKeyspace
RowUpdateBuilder adder =
new RowUpdateBuilder(Aggregates, timestamp, mutation) .clustering(aggregate.name().name, functionArgumentsList(aggregate));
+ CQL3Type stateCqlType = aggregate.stateType().asCQL3Type();
adder.add("return_type", aggregate.returnType().asCQL3Type().toString())
.add("state_func", aggregate.stateFunction().name().name)
- .add("state_type", aggregate.stateType() != null ? aggregate.stateType().asCQL3Type().toString() : null)
+ .add("state_type", aggregate.stateType() != null ? stateCqlType.toString() : null)
.add("final_func", aggregate.finalFunction() != null ? aggregate.finalFunction().name().name : null)
- .add("initcond", aggregate.initialCondition())
+ .add("initcond", aggregate.initialCondition() != null ? stateCqlType.asCQLLiteral(aggregate.initialCondition(), Server.CURRENT_VERSION) : null)
.build();
}
@@ -1219,7 +1221,7 @@ public final class SchemaKeyspace
FunctionName stateFunc = new FunctionName(ksName, (row.getString("state_func")));
FunctionName finalFunc = row.has("final_func") ? new FunctionName(ksName, row.getString("final_func")) : null;
AbstractType<?> stateType = row.has("state_type") ? parse(ksName, row.getString("state_type"), types) : null;
- ByteBuffer initcond = row.has("initcond") ? row.getBytes("initcond") : null;
+ ByteBuffer initcond = row.has("initcond") ? Terms.asBytes(ksName, row.getString("initcond"), stateType) : null;
try
{
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/serializers/AbstractTextSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/serializers/AbstractTextSerializer.java b/src/java/org/apache/cassandra/serializers/AbstractTextSerializer.java
index f1de6a4..4d2694e 100644
--- a/src/java/org/apache/cassandra/serializers/AbstractTextSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/AbstractTextSerializer.java
@@ -58,4 +58,32 @@ public abstract class AbstractTextSerializer implements TypeSerializer<String>
{
return String.class;
}
+
+ /**
+ * Generates CQL literal for TEXT/VARCHAR/ASCII types.
+ * Caveat: it does only generate literals with single quotes and not pg-style literals.
+ */
+ @Override
+ public void toCQLLiteral(ByteBuffer buffer, StringBuilder target)
+ {
+ if (buffer == null)
+ {
+ target.append("null");
+ }
+ else
+ {
+ String s = deserialize(buffer);
+
+ target.append('\'');
+ for (int i=0; i<s.length(); i++)
+ {
+ char c = s.charAt(i);
+ if (c == '\'')
+ target.append("''");
+ else
+ target.append(c);
+ }
+ target.append('\'');
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/serializers/BytesSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/serializers/BytesSerializer.java b/src/java/org/apache/cassandra/serializers/BytesSerializer.java
index 4dcaa82..85251b8 100644
--- a/src/java/org/apache/cassandra/serializers/BytesSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/BytesSerializer.java
@@ -52,4 +52,18 @@ public class BytesSerializer implements TypeSerializer<ByteBuffer>
{
return ByteBuffer.class;
}
+
+ @Override
+ public void toCQLLiteral(ByteBuffer buffer, StringBuilder target)
+ {
+ if (buffer == null)
+ {
+ target.append("null");
+ }
+ else
+ {
+ target.append("0x");
+ target.append(toString(deserialize(buffer)));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/serializers/TimestampSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/serializers/TimestampSerializer.java b/src/java/org/apache/cassandra/serializers/TimestampSerializer.java
index ab81fcc..01a85e0 100644
--- a/src/java/org/apache/cassandra/serializers/TimestampSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/TimestampSerializer.java
@@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
+import java.util.TimeZone;
import java.util.regex.Pattern;
import org.apache.commons.lang3.time.DateUtils;
@@ -73,7 +74,7 @@ public class TimestampSerializer implements TypeSerializer<Date>
"yyyy-MM-dd'T'HH:mm:ss.SSS z",
"yyyy-MM-dd'T'HH:mm:ss.SSS zz",
"yyyy-MM-dd'T'HH:mm:ss.SSS zzz",
- "yyyy-MM-dd'T'HH:mm:ss.SSSX",
+ "yyyy-MM-dd'T'HH:mm:ss.SSSX", // UTC_FORMAT
"yyyy-MM-dd'T'HH:mm:ss.SSSXX",
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX",
"yyyy-MM-dd",
@@ -96,6 +97,17 @@ public class TimestampSerializer implements TypeSerializer<Date>
}
};
+ private static final String UTC_FORMAT = dateStringPatterns[40];
+ private static final ThreadLocal<SimpleDateFormat> FORMATTER_UTC = new ThreadLocal<SimpleDateFormat>()
+ {
+ protected SimpleDateFormat initialValue()
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat(UTC_FORMAT);
+ sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
+ return sdf;
+ }
+ };
+
public static final SimpleDateFormat TO_JSON_FORMAT = new SimpleDateFormat(dateStringPatterns[15]);
public static final TimestampSerializer instance = new TimestampSerializer();
@@ -150,8 +162,26 @@ public class TimestampSerializer implements TypeSerializer<Date>
return value == null ? "" : FORMATTER.get().format(value);
}
+ public String toStringUTC(Date value)
+ {
+ return value == null ? "" : FORMATTER_UTC.get().format(value);
+ }
+
public Class<Date> getType()
{
return Date.class;
}
+
+ /**
+ * Builds CQL literal for a timestamp using time zone UTC and fixed date format.
+ * @see #FORMATTER_UTC
+ */
+ @Override
+ public void toCQLLiteral(ByteBuffer buffer, StringBuilder target)
+ {
+ if (buffer == null || !buffer.hasRemaining())
+ target.append("null");
+ else
+ target.append(FORMATTER_UTC.get().format(deserialize(buffer)));
+ }
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e94032a2/src/java/org/apache/cassandra/serializers/TypeSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/serializers/TypeSerializer.java b/src/java/org/apache/cassandra/serializers/TypeSerializer.java
index cddef08..e7bb830 100644
--- a/src/java/org/apache/cassandra/serializers/TypeSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/TypeSerializer.java
@@ -34,5 +34,13 @@ public interface TypeSerializer<T>
public String toString(T value);
public Class<T> getType();
+
+ public default void toCQLLiteral(ByteBuffer buffer, StringBuilder target)
+ {
+ if (buffer == null || !buffer.hasRemaining())
+ target.append("null");
+ else
+ target.append(toString(deserialize(buffer)));
+ }
}