com.datastax.driver.core.DataType.Name Java Examples
The following examples show how to use
com.datastax.driver.core.DataType.Name.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraRowMapperFn.java From DataflowTemplates with Apache License 2.0 | 4 votes |
/** * This method converts Cassandra {@link DataType} to Beam {@link FieldType}. Tuples are as of yet * not supported as there is no corresponding type in the Beam {@link Schema}. * * @param type the Cassandra DataType to be converted * @return the corresponding Beam Schema field type. * @see org.apache.beam.sdk.schemas.Schema.FieldType * @see com.datastax.driver.core.DataType * @link <a href="https://docs.datastax.com/en/cql/3.3/cql/cql_reference/tupleType.html">Cassandra * Tuple</a> */ private FieldType toBeamRowType(DataType type) { DataType.Name n = type.getName(); switch (n) { case TIMESTAMP: case DATE: return FieldType.DATETIME; case BLOB: return FieldType.BYTES; case BOOLEAN: return FieldType.BOOLEAN; case DECIMAL: return FieldType.DECIMAL; case DOUBLE: return FieldType.DOUBLE; case FLOAT: return FieldType.FLOAT; case INT: return FieldType.INT32; case VARINT: return FieldType.DECIMAL; case SMALLINT: return FieldType.INT16; case TINYINT: return FieldType.BYTE; case LIST: case SET: DataType innerType = type.getTypeArguments().get(0); return FieldType.array(toBeamRowType(innerType)); case MAP: DataType kDataType = type.getTypeArguments().get(0); DataType vDataType = type.getTypeArguments().get(1); FieldType k = toBeamRowType(kDataType); FieldType v = toBeamRowType(vDataType); return FieldType.map(k, v); case VARCHAR: case TEXT: case INET: case UUID: case TIMEUUID: case ASCII: return FieldType.STRING; case BIGINT: case COUNTER: case TIME: return FieldType.INT64; default: throw new UnsupportedOperationException("Datatype " + type.getName() + " not supported."); } }