Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle invalid types with an informative error message, update docs. #150

Merged
merged 1 commit into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/standalone/priming-cluster-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The Java Datastax Driver looks in the system.local table for the cluster\_name.
],
"result": "success",
"column_types": {
"tokens": "set"
"tokens": "set<text>"
}
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ The 1.* driver executes a different query;
],
"result": "success",
"column_types": {
"tokens": "Set"
"tokens": "set<text>"
}
}
}
Expand All @@ -80,7 +80,7 @@ If you're using the Scassandra java client you'll need something like:


```java
Map<String, ColumnTypes> columnTypes = ImmutableMap.of("tokens",ColumnTypes.Set);
Map<String, ColumnTypes> columnTypes = ImmutableMap.of("tokens",SetType.set(PrimitiveType.TEXT));
String query = "SELECT cluster_name, data_center, rack, tokens, partitioner FROM system.local WHERE key='local'";
Map<String, Object> row = new HashMap<>();
row.put("cluster_name", CUSTOM_CLUSTER_NAME);
Expand All @@ -94,4 +94,4 @@ If you're using the Scassandra java client you'll need something like:
.withRows(row)
.build();
primingClient.primeQuery(prime);
```
```
2 changes: 1 addition & 1 deletion docs/standalone/priming-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Varchars can be primed in two ways.
},
"then": {
"rows" :[{"column1": ["one", "two", "three"]}] ,
"column_types" : { "column1" : "set"}
"column_types" : { "column1" : "set<text>"}
}
}
```
Expand Down
6 changes: 3 additions & 3 deletions docs/standalone/using-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Example prime:
"partitioner": "varchar",
"data_center": "varchar",
"rack": "varchar",
"tokens": "set",
"tokens": "set<text>",
"release_version": "varchar"
}
}
Expand Down Expand Up @@ -82,8 +82,8 @@ Example prime:
],
"result": "success",
"column_types": {
"tokens": "uuid"
"schema_version": "uuid"
}
}
}
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import com.typesafe.scalalogging.LazyLogging
import org.scassandra.cql._
import org.scassandra.server.cqlmessages.{ProtocolVersion, CqlProtocolHelper}

import scala.util.{Failure, Success, Try}

abstract class ColumnType[T](val code : Short, val stringRep: String) extends LazyLogging {
implicit val byteOrder = CqlProtocolHelper.byteOrder

Expand Down Expand Up @@ -139,12 +141,7 @@ object ColumnType extends LazyLogging {
serializer(input, entrySerializer)
}

def fromString(string: String): Option[ColumnType[_]] = {

val cqlTypeFactory = new CqlTypeFactory
val cqlType = cqlTypeFactory.buildType(string)

logger.trace(s"Java type $cqlType")
def fromString(string: String): Try[ColumnType[_]] = {

def convertJavaToScalaType(javaType: CqlType): ColumnType[_] = {
javaType match {
Expand All @@ -155,8 +152,17 @@ object ColumnType extends LazyLogging {
}
}

val parsedType = Some(convertJavaToScalaType(cqlType))
logger.info(s"Type is $parsedType")
parsedType
val cqlTypeFactory = new CqlTypeFactory

try {
val cqlType = cqlTypeFactory.buildType(string)

logger.trace(s"Java type $cqlType")
val parsedType = Success(convertJavaToScalaType(cqlType))
logger.info(s"Type is $parsedType")
parsedType
} catch {
case e: Exception => Failure(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import spray.httpx.SprayJsonSupport
import spray.json._

import scala.collection.Set
import scala.util.{Failure, Success => TSuccess}

object PrimingJsonImplicits extends DefaultJsonProtocol with SprayJsonSupport with LazyLogging {

Expand Down Expand Up @@ -121,10 +122,10 @@ object PrimingJsonImplicits extends DefaultJsonProtocol with SprayJsonSupport wi

def read(value: JsValue) = value match {
case JsString(string) => ColumnType.fromString(string) match {
case Some(columnType) => columnType
case None =>
logger.warn(s"Received invalid column type $string")
throw new IllegalArgumentException("Not a valid column type " + string)
case TSuccess(columnType) => columnType
case Failure(e) =>
logger.warn(s"Received invalid column type '$string'", e)
throw new IllegalArgumentException(s"Not a valid column type '$string'")
}
case _ => throw new IllegalArgumentException("Expected ColumnType as JsString")
}
Expand Down