List of usage examples for org.apache.cassandra.db.marshal DateType instance
DateType instance
To view the source code for org.apache.cassandra.db.marshal DateType instance.
Click Source Link
From source file:clojurewerkz.cassaforte.Codec.java
License:Apache License
private static AbstractType getCodecInternal(DataType type) { switch (type.getName()) { case ASCII:/*from ww w . ja v a 2s . com*/ return AsciiType.instance; case BIGINT: return LongType.instance; case BLOB: return BytesType.instance; case BOOLEAN: return BooleanType.instance; case COUNTER: return CounterColumnType.instance; case DECIMAL: return DecimalType.instance; case DOUBLE: return DoubleType.instance; case FLOAT: return FloatType.instance; case INET: return InetAddressType.instance; case INT: return Int32Type.instance; case TEXT: return UTF8Type.instance; case TIMESTAMP: return DateType.instance; case UUID: return UUIDType.instance; case VARCHAR: return UTF8Type.instance; case VARINT: return IntegerType.instance; case TIMEUUID: return TimeUUIDType.instance; case LIST: return ListType.getInstance(getCodec(type.getTypeArguments().get(0))); case SET: return SetType.getInstance(getCodec(type.getTypeArguments().get(0))); case MAP: return MapType.getInstance(getCodec(type.getTypeArguments().get(0)), getCodec(type.getTypeArguments().get(1))); default: throw new RuntimeException("Unknown type"); } }
From source file:com.datastax.driver.core.ArrayBackedRow.java
License:Apache License
public Date getDate(int i) { metadata.checkType(i, DataType.Name.TIMESTAMP); ByteBuffer value = data.get(i); if (value == null || value.remaining() == 0) return null; return DateType.instance.compose(value); }
From source file:com.datastax.driver.core.BoundStatement.java
License:Apache License
/** * Set the {@code i}th value to the provided date. * * @param i the index of the variable to set. * @param v the value to set.//w ww. j a v a 2 s. c om * @return this BoundStatement. * * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. * @throws InvalidTypeException if column {@code i} is not of type TIMESTAMP. */ public BoundStatement setDate(int i, Date v) { metadata().checkType(i, DataType.Name.TIMESTAMP); return setValue(i, v == null ? null : DateType.instance.decompose(v)); }
From source file:com.datastax.driver.core.Codec.java
License:Apache License
private static AbstractType<?> getCodecInternal(DataType type) { switch (type.getName()) { case ASCII://w w w. ja v a 2 s. c o m return AsciiType.instance; case BIGINT: return LongType.instance; case BLOB: return BytesType.instance; case BOOLEAN: return BooleanType.instance; case COUNTER: return CounterColumnType.instance; case DECIMAL: return DecimalType.instance; case DOUBLE: return DoubleType.instance; case FLOAT: return FloatType.instance; case INET: return InetAddressType.instance; case INT: return Int32Type.instance; case TEXT: return UTF8Type.instance; case TIMESTAMP: return DateType.instance; case UUID: return UUIDType.instance; case VARCHAR: return UTF8Type.instance; case VARINT: return IntegerType.instance; case TIMEUUID: return TimeUUIDType.instance; case LIST: return ListType.getInstance(getCodec(type.getTypeArguments().get(0))); case SET: return SetType.getInstance(getCodec(type.getTypeArguments().get(0))); case MAP: return MapType.getInstance(getCodec(type.getTypeArguments().get(0)), getCodec(type.getTypeArguments().get(1))); // We don't interpret custom values in any way case CUSTOM: return BytesType.instance; default: throw new RuntimeException("Unknown type"); } }
From source file:com.datastax.driver.core.Row.java
License:Apache License
/** * Returns the {@code i}th value of this row as a date. * * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. * @return the value of the {@code i}th column in this row as a data. If the * value is NULL, {@code null} is returned. * * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. * @throws InvalidTypeException if column {@code i} is not of type TIMESTAMP. *//*from www . j av a 2 s .co m*/ public Date getDate(int i) { metadata.checkType(i, DataType.Name.TIMESTAMP); ByteBuffer value = data.get(i); if (value == null || value.remaining() == 0) return null; return DateType.instance.compose(value); }
From source file:com.dse.pig.udfs.AbstractCassandraStorage.java
License:Apache License
/** set the value to the position of the tuple */ protected void setTupleValue(Tuple pair, int position, Object value) throws ExecException { if (value instanceof BigInteger) pair.set(position, ((BigInteger) value).intValue()); else if (value instanceof ByteBuffer) pair.set(position, new DataByteArray(ByteBufferUtil.getArray((ByteBuffer) value))); else if (value instanceof Date) pair.set(position, DateType.instance.decompose((Date) value).getLong()); else if (value instanceof java.util.UUID) pair.set(position, value.toString()); else/* w ww .ja va 2s . c om*/ pair.set(position, value.toString()); }
From source file:com.impetus.client.cassandra.common.CassandraUtilities.java
License:Apache License
/** * @param value/*from w w w.j av a 2 s.c o m*/ * @param f * @return */ public static ByteBuffer toBytes(Object value, Class<?> clazz) { if (clazz.isAssignableFrom(String.class)) { return UTF8Type.instance.decompose((String) value); } else if (clazz.equals(int.class) || clazz.isAssignableFrom(Integer.class)) { return Int32Type.instance.decompose(Integer.parseInt(value.toString())); } else if (clazz.equals(long.class) || clazz.isAssignableFrom(Long.class)) { return LongType.instance.decompose(Long.parseLong(value.toString())); } else if (clazz.equals(boolean.class) || clazz.isAssignableFrom(Boolean.class)) { return BooleanType.instance.decompose(Boolean.valueOf(value.toString())); } else if (clazz.equals(double.class) || clazz.isAssignableFrom(Double.class)) { return DoubleType.instance.decompose(Double.valueOf(value.toString())); } else if (clazz.isAssignableFrom(java.util.UUID.class)) { return UUIDType.instance.decompose(UUID.fromString(value.toString())); } else if (clazz.equals(float.class) || clazz.isAssignableFrom(Float.class)) { return FloatType.instance.decompose(Float.valueOf(value.toString())); } else if (clazz.isAssignableFrom(Date.class)) { DateAccessor dateAccessor = new DateAccessor(); return DateType.instance.decompose((Date) value); } else { if (value.getClass().isAssignableFrom(String.class)) { value = PropertyAccessorFactory.getPropertyAccessor(clazz).fromString(clazz, value.toString()); } return BytesType.instance .decompose(ByteBuffer.wrap(PropertyAccessorFactory.getPropertyAccessor(clazz).toBytes(value))); } }
From source file:org.apache.hadoop.hive.serde2.lazy.LazyCassandraUtils.java
License:Apache License
public static AbstractType getCassandraType(PrimitiveObjectInspector oi) { switch (oi.getPrimitiveCategory()) { case BOOLEAN: return BooleanType.instance; case INT:/*w w w . ja va 2s . co m*/ return Int32Type.instance; case LONG: return LongType.instance; case FLOAT: return FloatType.instance; case DOUBLE: return DoubleType.instance; case STRING: return UTF8Type.instance; case BYTE: case SHORT: case BINARY: return BytesType.instance; case TIMESTAMP: return DateType.instance; default: throw new RuntimeException("Hive internal error."); } }
From source file:org.pentaho.cassandra.CassandraColumnMetaData.java
License:Apache License
/** * Static utility method that converts a Kettle value into an appropriately * encoded CQL string./*from w w w. j a v a2s .c om*/ * * @param vm the ValueMeta for the Kettle value * @param value the actual Kettle value * @return an appropriately encoded CQL string representation of the value, * suitable for using in an CQL query. * @throws KettleValueException if there is an error converting. */ public static String kettleValueToCQL(ValueMetaInterface vm, Object value) throws KettleValueException { switch (vm.getType()) { case ValueMetaInterface.TYPE_STRING: { UTF8Type u = UTF8Type.instance; String toConvert = vm.getString(value); ByteBuffer decomposed = u.decompose(toConvert); String cassandraString = u.getString(decomposed); return escapeSingleQuotes(cassandraString); } case ValueMetaInterface.TYPE_BIGNUMBER: { DecimalType dt = DecimalType.instance; BigDecimal toConvert = vm.getBigNumber(value); ByteBuffer decomposed = dt.decompose(toConvert); String cassandraString = dt.getString(decomposed); return cassandraString; } case ValueMetaInterface.TYPE_BOOLEAN: { BooleanType bt = BooleanType.instance; Boolean toConvert = vm.getBoolean(value); ByteBuffer decomposed = bt.decompose(toConvert); String cassandraString = bt.getString(decomposed); return escapeSingleQuotes(cassandraString); } case ValueMetaInterface.TYPE_INTEGER: { LongType lt = LongType.instance; Long toConvert = vm.getInteger(value); ByteBuffer decomposed = lt.decompose(toConvert); String cassandraString = lt.getString(decomposed); return cassandraString; } case ValueMetaInterface.TYPE_NUMBER: { DoubleType dt = DoubleType.instance; Double toConvert = vm.getNumber(value); ByteBuffer decomposed = dt.decompose(toConvert); String cassandraString = dt.getString(decomposed); return cassandraString; } case ValueMetaInterface.TYPE_DATE: DateType d = DateType.instance; Date toConvert = vm.getDate(value); ByteBuffer decomposed = d.decompose(toConvert); String cassandraFormattedDateString = d.getString(decomposed); return escapeSingleQuotes(cassandraFormattedDateString); case ValueMetaInterface.TYPE_BINARY: case ValueMetaInterface.TYPE_SERIALIZABLE: throw new KettleValueException( BaseMessages.getString(PKG, "CassandraColumnMetaData.Error.CantConvertBinaryToCQL")); } throw new KettleValueException(BaseMessages.getString(PKG, "CassandraColumnMetaData.Error.CantConvertType", vm.getName(), vm.getTypeDesc())); }
From source file:org.pentaho.cassandra.CassandraColumnMetaData.java
License:Apache License
/** * Static utility to decompose a Kettle value to a ByteBuffer. Note - does not * check if the kettle value is null.// w w w . j av a 2 s.c o m * * @param vm the ValueMeta for the Kettle value * @param value the actual Kettle value * @return a ByteBuffer encapsulating the bytes for the decomposed value * @throws KettleException if a problem occurs */ public ByteBuffer kettleValueToByteBuffer(ValueMetaInterface vm, Object value, boolean isKey) throws KettleException { String fullTransCoder = m_defaultValidationClass; // check the key first if (isKey) { fullTransCoder = m_keyValidator; } else { fullTransCoder = m_columnMeta.get(vm.getName()); if (fullTransCoder == null) { // use default if not in column meta data fullTransCoder = m_defaultValidationClass; } } String transCoder = fullTransCoder; // if it's a composite type make sure that we check only against the // primary type if (transCoder.indexOf('(') > 0) { transCoder = transCoder.substring(0, transCoder.indexOf('(')); } ByteBuffer decomposed = null; if (transCoder.indexOf("UTF8Type") > 0) { UTF8Type u = UTF8Type.instance; decomposed = u.decompose(vm.getString(value)); } else if (transCoder.indexOf("AsciiType") > 0) { AsciiType at = AsciiType.instance; decomposed = at.decompose(vm.getString(value)); } else if (transCoder.indexOf("LongType") > 0) { LongType lt = LongType.instance; decomposed = lt.decompose(vm.getInteger(value)); } else if (transCoder.indexOf("DoubleType") > 0) { DoubleType dt = DoubleType.instance; decomposed = dt.decompose(vm.getNumber(value)); } else if (transCoder.indexOf("DateType") > 0) { DateType dt = DateType.instance; decomposed = dt.decompose(vm.getDate(value)); } else if (transCoder.indexOf("IntegerType") > 0) { IntegerType it = IntegerType.instance; decomposed = it.decompose(vm.getBigNumber(value).toBigInteger()); } else if (transCoder.indexOf("FloatType") > 0) { FloatType ft = FloatType.instance; decomposed = ft.decompose(vm.getNumber(value).floatValue()); } else if (transCoder.indexOf("LexicalUUIDType") > 0) { LexicalUUIDType lt = LexicalUUIDType.instance; UUID uuid = UUID.fromString((vm.getString(value))); decomposed = lt.decompose(uuid); } else if (transCoder.indexOf("UUIDType") > 0) { UUIDType ut = UUIDType.instance; UUID uuid = UUID.fromString((vm.getString(value))); decomposed = ut.decompose(uuid); } else if (transCoder.indexOf("BooleanType") > 0) { BooleanType bt = BooleanType.instance; decomposed = bt.decompose(vm.getBoolean(value)); } else if (transCoder.indexOf("Int32Type") > 0) { Int32Type it = Int32Type.instance; decomposed = it.decompose(vm.getInteger(value).intValue()); } else if (transCoder.indexOf("DecimalType") > 0) { DecimalType dt = DecimalType.instance; decomposed = dt.decompose(vm.getBigNumber(value)); } else if (transCoder.indexOf("DynamicCompositeType") > 0) { AbstractType serializer = null; if (vm.isString()) { try { serializer = TypeParser.parse(fullTransCoder); decomposed = ((DynamicCompositeType) serializer).fromString(vm.getString(value)); } catch (ConfigurationException e) { throw new KettleException(e.getMessage(), e); } catch (SyntaxException e) { throw new KettleException(e.getMessage(), e); } } else { throw new KettleException(BaseMessages.getString(PKG, "CassandraColumnMetaData.Error.CantConvertTypeThrift", vm.getTypeDesc(), fullTransCoder)); } } else if (transCoder.indexOf("CompositeType") > 0) { AbstractType serializer = null; if (vm.isString()) { try { serializer = TypeParser.parse(fullTransCoder); decomposed = ((CompositeType) serializer).fromString(vm.toString()); } catch (ConfigurationException e) { throw new KettleException(e.getMessage(), e); } catch (SyntaxException e) { throw new KettleException(e.getMessage(), e); } } else { throw new KettleException(BaseMessages.getString(PKG, "CassandraColumnMetaData.Error.CantConvertTypeThrift", vm.getTypeDesc(), fullTransCoder)); } } if (decomposed == null) { throw new KettleException(BaseMessages.getString(PKG, "CassandraColumnMetaData.Error.UnableToConvertValue", vm.getName())); } return decomposed; }