Skip to content
Browse files

Deprecate but keep strings-as-blob support for now for compatibility …

…sake
  • Loading branch information...
1 parent 60acf0d commit b251e7aec03273ac14eeae79bee13422068d508b @pcmanus pcmanus committed
Showing with 28 additions and 2 deletions.
  1. +4 −1 NEWS.txt
  2. +2 −1 doc/cql3/CQL.textile
  3. +22 −0 src/java/org/apache/cassandra/cql3/Term.java
View
5 NEWS.txt
@@ -16,7 +16,10 @@ Upgrading
- CQL3 type validation for constants has been fixed, which may require
fixing queries that were relying on the previous loose validation. Please
refer to the CQL3 documentation (http://cassandra.apache.org/doc/cql3/CQL.html)
- and in particular the changelog section for more details.
+ and in particular the changelog section for more details. Please note in
+ particular that inputing blobs as strings constants is now deprecated (in
+ favor of blob constants) and its support will be removed in a future
+ version.
1.2.1
View
3 doc/cql3/CQL.textile
@@ -1007,7 +1007,8 @@ The following describes the addition/changes brought for each version of CQL.
h3. 3.0.2
-- Type validation for the "constants":#constants has been fixed. For instance, the implementation used to allow @'2'@ as a valid value for an @int@ column (interpreting it has the equivalent of @2@), or @42@ as a valid @blob@ value (in which case @42@ was interpreted as an hexadecimal representation of the blob). This is no longer the case, type validation of constants is now more strict. See the "data types":#dataTypes section for details on which constant is allowed for which type, but note that this let to the introduction of "blobs constants":#constants.
+- Type validation for the "constants":#constants has been fixed. For instance, the implementation used to allow @'2'@ as a valid value for an @int@ column (interpreting it has the equivalent of @2@), or @42@ as a valid @blob@ value (in which case @42@ was interpreted as an hexadecimal representation of the blob). This is no longer the case, type validation of constants is now more strict. See the "data types":#dataTypes section for details on which constant is allowed for which type.
+- The type validation fixed of the previous point has lead to the introduction of "blobs constants":#constants to allow inputing blobs. Do note that while inputing blobs as strings constant is still supported by this version (to allow smoother transition to blob constant), it is now deprecated (in particular the "data types":#dataTypes section does not list strings constants as valid blobs) and will be removed by a future version. If you were using strings as blobs, you should thus update your client code asap to switch blob constants.
h3. 3.0.1
View
22 src/java/org/apache/cassandra/cql3/Term.java
@@ -22,6 +22,9 @@
import java.util.List;
import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.BytesType;
import org.apache.cassandra.db.marshal.MarshalException;
@@ -30,6 +33,8 @@
/** A term parsed from a CQL statement. */
public class Term
{
+ private static final Logger logger = LoggerFactory.getLogger(Term.class);
+
public enum Type
{
STRING, INTEGER, UUID, FLOAT, BOOLEAN, HEX, QMARK;
@@ -60,6 +65,9 @@ else if (type == CqlParser.QMARK)
public final int bindIndex;
public final boolean isToken;
+ // For transition post-5198, see below
+ private static volatile boolean stringAsBlobWarningLogged = false;
+
// This is a hack for the timeuuid functions (minTimeuuid, maxTimeuuid, now) because instead of handling them as
// true function we let the TimeUUID.fromString() method handle it. We should probably clean that up someday
private final boolean skipTypeValidation;
@@ -168,6 +176,20 @@ public void validateType(String identifier, AbstractType<?> validator) throws In
if (!supported.contains(type))
{
+ // Blobs should now be inputed as hexadecimal constants. However, to allow people to upgrade, we still allow
+ // blob-as-strings, even though it is deprecated (see #5198).
+ if (type == Type.STRING && validator instanceof BytesType)
+ {
+ if (!stringAsBlobWarningLogged)
+ {
+ stringAsBlobWarningLogged = true;
+ logger.warn("Inputing CLQ3 blobs as strings (like %s = '%s') is now deprecated and will be removed in a future version. "
+ + "You should convert client code to use a blob constant (%s = %s) instead (see http://cassandra.apache.org/doc/cql3/CQL.html changelog section for more info).",
+ identifier, text, identifier, "0x" + text);
+ }
+ return;
+ }
+
// TODO: Ideallly we'd keep the declared CQL3 type of columns and use that in the following message, instead of the AbstracType class name.
throw new InvalidRequestException(String.format("Invalid %s constant for %s of type %s", type, identifier, validator.asCQL3Type()));
}

0 comments on commit b251e7a

Please sign in to comment.
Something went wrong with that request. Please try again.