com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 0, column type is counter but class java.lang.Integer provided

DataStax JIRA | mkjellman | 4 years ago
  1. 0

    When inserting a java.lang.Number into Cassandra, the Datastax driver effectively expects an exact match on the class. This means that callers are expected to pre-coerce their inputs, which is surprising and fragile. (Some libraries, such as Jackson, are fond of producing different Number types depending on the magnitude of the data.) This issue was encountered while using the Cassaforte library from Clojurewerkz (which uses the datastax lib v1.0.3) The stack trace is below: {noformat} com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 3 of CQL type bigint, expecting class java.lang.Long but class java.lang.Integer provided at com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:190) ~[cassandra-driver-core-1.0.3.jar:na] at com.datastax.driver.core.PreparedStatement.bind(PreparedStatement.java:158) ~[cassandra-driver-core-1.0.3.jar:na] at clojurewerkz.cassaforte.client$build_statement.invoke(client.clj:170) ~[classes/:na] at clojurewerkz.cassaforte.client$execute.doInvoke(client.clj:291) ~[classes/:na] at clojure.lang.RestFn.invoke(RestFn.java:457) ~[clojure-1.4.0.jar:na] at clojurewerkz.cassaforte.multi.cql$execute_.invoke(cql.clj:17) ~[classes/:na] at clojurewerkz.cassaforte.multi.cql$insert.doInvoke(cql.clj:132) ~[classes/:na] ... {noformat}

    DataStax JIRA | 3 years ago | Tim McCormack
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 3 of CQL type bigint, expecting class java.lang.Long but class java.lang.Integer provided
  2. Speed up your debug routine!

    Automated exception search integrated into your IDE

  3. 0

    When inserting a java.lang.Number into Cassandra, the Datastax driver effectively expects an exact match on the class. This means that callers are expected to pre-coerce their inputs, which is surprising and fragile. (Some libraries, such as Jackson, are fond of producing different Number types depending on the magnitude of the data.) This issue was encountered while using the Cassaforte library from Clojurewerkz (which uses the datastax lib v1.0.3) The stack trace is below: {noformat} com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 3 of CQL type bigint, expecting class java.lang.Long but class java.lang.Integer provided at com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:190) ~[cassandra-driver-core-1.0.3.jar:na] at com.datastax.driver.core.PreparedStatement.bind(PreparedStatement.java:158) ~[cassandra-driver-core-1.0.3.jar:na] at clojurewerkz.cassaforte.client$build_statement.invoke(client.clj:170) ~[classes/:na] at clojurewerkz.cassaforte.client$execute.doInvoke(client.clj:291) ~[classes/:na] at clojure.lang.RestFn.invoke(RestFn.java:457) ~[clojure-1.4.0.jar:na] at clojurewerkz.cassaforte.multi.cql$execute_.invoke(cql.clj:17) ~[classes/:na] at clojurewerkz.cassaforte.multi.cql$insert.doInvoke(cql.clj:132) ~[classes/:na] ... {noformat}

    DataStax JIRA | 3 years ago | Tim McCormack
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 3 of CQL type bigint, expecting class java.lang.Long but class java.lang.Integer provided
  4. 0

    *_Final fix:_* We're going to forbid bind markers in query builder methods that add a single element: {{update("foo").with(add("s", bindMarker())).where(eq("k", 1));}} The reason is that this would generate {{UPDATE foo SET s = s + {?} WHERE k = 1}}, which gets rejected by Cassandra (you can't bind an element inside a collection). So attempting to do this will throw an exception, the workaround is the one I mentioned in the comments: use `addAll` and then bind a singleton collection. This also applies to list append/prepend. ----- *_Initial issue description:_* With a table definition {code:java} create table user ( id uuid, addr_set set<text>, primary key ( id ) ); {code} Updating as {code:java} Update.Where u = QueryBuilder.update( "ks", "user" ) .with( QueryBuilder.add( "addr_set", bindMarker() ) ) .where( QueryBuilder.eq( "id", UUID.fromString( "valid uuid" ) ) ); PreparedStatement ps = session.prepare( u ); ResultSet resultSet = session.execute( ps.bind( "my address" ) ); {code} throws an exception {code:java} com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 0, column is a set but class java.lang.String provided at com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:169) at com.datastax.driver.core.DefaultPreparedStatement.bind(DefaultPreparedStatement.java:103) {code} Executing without preparing works fine.

    DataStax JIRA | 2 years ago | Kairat Beq
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 0, column is a set but class java.lang.String provided

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. com.datastax.driver.core.exceptions.InvalidTypeException

      Invalid type for value 0, column type is counter but class java.lang.Integer provided

      at com.datastax.driver.core.BoundStatement.bind()
    2. DataStax Java Driver for Apache Cassandra - Core
      PreparedStatement.bind
      1. com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:168)
      2. com.datastax.driver.core.PreparedStatement.bind(PreparedStatement.java:128)
      2 frames