List of usage examples for org.apache.cassandra.db.marshal AbstractType getString
public String getString(Collection<ByteBuffer> names)
From source file:com.dse.pig.udfs.AbstractCassandraStorage.java
License:Apache License
protected Object cassandraToObj(AbstractType validator, ByteBuffer value) { if (validator instanceof DecimalType || validator instanceof InetAddressType) return validator.getString(value); else//from w ww.j a va 2 s.c om return validator.compose(value); }
From source file:com.dse.pig.udfs.CqlStorage.java
License:Apache License
private Object cassandraToPigData(Object obj, AbstractType validator) { if (validator instanceof DecimalType || validator instanceof InetAddressType) return validator.getString(validator.decompose(obj)); return obj;/*from www . j av a 2 s .c o m*/ }
From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java
License:Apache License
/** * Writes the supplied ColumnDef to the StringBuilder as a cli script. * * @param output The File to write to.//from w ww . jav a2s .c o m * @param cfDef The CfDef as a source for comparator/validator * @param colDef The Column Definition to export */ private void showColumnMeta(PrintStream output, CfDef cfDef, ColumnDef colDef) { output.append(NEWLINE + TAB + TAB + "{"); final AbstractType<?> comparator = getFormatType( cfDef.column_type.equals("Super") ? cfDef.subcomparator_type : cfDef.comparator_type); output.append( "column_name : '" + CliUtils.escapeSQLString(comparator.getString(colDef.name)) + "'," + NEWLINE); String validationClass = normaliseType(colDef.validation_class, "org.apache.cassandra.db.marshal"); output.append(TAB + TAB + "validation_class : " + CliUtils.escapeSQLString(validationClass)); if (colDef.isSetIndex_name()) { output.append(",").append(NEWLINE) .append(TAB + TAB + "index_name : '" + CliUtils.escapeSQLString(colDef.index_name) + "'," + NEWLINE) .append(TAB + TAB + "index_type : " + CliUtils.escapeSQLString(Integer.toString(colDef.index_type.getValue()))); if (colDef.index_options != null && !colDef.index_options.isEmpty()) { output.append(",").append(NEWLINE); output.append(TAB + TAB + "index_options : {" + NEWLINE); int numOpts = colDef.index_options.size(); for (Map.Entry<String, String> entry : colDef.index_options.entrySet()) { String option = CliUtils.escapeSQLString(entry.getKey()); String optionValue = CliUtils.escapeSQLString(entry.getValue()); output.append(TAB + TAB + TAB).append("'" + option + "' : '").append(optionValue).append("'"); if (--numOpts > 0) output.append(",").append(NEWLINE); } output.append("}"); } } output.append("}"); }
From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java
License:Apache License
private void describeColumnFamily(KsDef ks_def, CfDef cf_def, NodeProbe probe) throws TException { // fetching bean for current column family store ColumnFamilyStoreMBean cfMBean = (probe == null) ? null : probe.getCfsProxy(ks_def.getName(), cf_def.getName()); boolean isSuper = cf_def.column_type.equals("Super"); sessionState.out.printf(" ColumnFamily: %s%s%n", cf_def.name, isSuper ? " (Super)" : ""); if (cf_def.comment != null && !cf_def.comment.isEmpty()) sessionState.out.printf(" \"%s\"%n", cf_def.comment); if (cf_def.key_validation_class != null) sessionState.out.printf(" Key Validation Class: %s%n", cf_def.key_validation_class); if (cf_def.default_validation_class != null) sessionState.out.printf(" Default column value validator: %s%n", cf_def.default_validation_class); sessionState.out.printf(" Cells sorted by: %s%s%n", cf_def.comparator_type, cf_def.column_type.equals("Super") ? "/" + cf_def.subcomparator_type : ""); sessionState.out.printf(" GC grace seconds: %s%n", cf_def.gc_grace_seconds); sessionState.out.printf(" Compaction min/max thresholds: %s/%s%n", cf_def.min_compaction_threshold, cf_def.max_compaction_threshold); sessionState.out.printf(" Read repair chance: %s%n", cf_def.read_repair_chance); sessionState.out.printf(" DC Local Read repair chance: %s%n", cf_def.dclocal_read_repair_chance); sessionState.out.printf(" Populate IO Cache on flush: %b%n", cf_def.populate_io_cache_on_flush); sessionState.out.printf(" Replicate on write: %s%n", cf_def.replicate_on_write); sessionState.out.printf(" Caching: %s%n", cf_def.caching); sessionState.out.printf(" Bloom Filter FP chance: %s%n", cf_def.isSetBloom_filter_fp_chance() ? cf_def.bloom_filter_fp_chance : "default"); // if we have connection to the cfMBean established if (cfMBean != null) sessionState.out.printf(" Built indexes: %s%n", cfMBean.getBuiltIndexes()); if (cf_def.getColumn_metadataSize() != 0) { String leftSpace = " "; String columnLeftSpace = leftSpace + " "; String compareWith = isSuper ? cf_def.subcomparator_type : cf_def.comparator_type; AbstractType<?> columnNameValidator = getFormatType(compareWith); sessionState.out.println(leftSpace + "Column Metadata:"); for (ColumnDef columnDef : cf_def.getColumn_metadata()) { String columnName = columnNameValidator.getString(columnDef.name); if (columnNameValidator instanceof BytesType) { try { String columnString = UTF8Type.instance.getString(columnDef.name); columnName = columnString + " (" + columnName + ")"; } catch (MarshalException e) { // guess it wasn't a utf8 column name after all }/*from ww w . ja v a2s. co m*/ } sessionState.out.println(leftSpace + " Column Name: " + columnName); sessionState.out.println(columnLeftSpace + "Validation Class: " + columnDef.getValidation_class()); if (columnDef.isSetIndex_name()) sessionState.out.println(columnLeftSpace + "Index Name: " + columnDef.getIndex_name()); if (columnDef.isSetIndex_type()) sessionState.out.println(columnLeftSpace + "Index Type: " + columnDef.getIndex_type().name()); if (columnDef.isSetIndex_options()) sessionState.out.println(columnLeftSpace + "Index Options: " + columnDef.getIndex_options()); } } sessionState.out.printf(" Compaction Strategy: %s%n", cf_def.compaction_strategy); if (cf_def.compaction_strategy_options != null && !cf_def.compaction_strategy_options.isEmpty()) { sessionState.out.println(" Compaction Strategy Options:"); for (Map.Entry<String, String> e : cf_def.compaction_strategy_options.entrySet()) sessionState.out.printf(" %s: %s%n", e.getKey(), e.getValue()); } if (cf_def.compression_options != null && !cf_def.compression_options.isEmpty()) { sessionState.out.println(" Compression Options:"); for (Map.Entry<String, String> e : cf_def.compression_options.entrySet()) sessionState.out.printf(" %s: %s%n", e.getKey(), e.getValue()); } }
From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java
License:Apache License
/** * Prints out KeySlice list/* w ww. j av a2s . c o m*/ * @param columnFamilyDef - column family definition * @param slices - list of the KeySlice's to print out * @throws NotFoundException - column not found * @throws TException - transfer is broken * @throws IllegalAccessException - can't do operation * @throws InstantiationException - can't instantiate a class * @throws NoSuchFieldException - column not found */ private void printSliceList(CfDef columnFamilyDef, List<KeySlice> slices) throws NotFoundException, TException, IllegalAccessException, InstantiationException, NoSuchFieldException, CharacterCodingException { AbstractType<?> validator; String columnFamilyName = columnFamilyDef.getName(); AbstractType<?> keyComparator = getKeyComparatorForCF(columnFamilyName); for (KeySlice ks : slices) { String keyName = (keyComparator == null) ? ByteBufferUtil.string(ks.key) : keyComparator.getString(ks.key); sessionState.out.printf("-------------------%n"); sessionState.out.printf("RowKey: %s%n", keyName); Iterator<ColumnOrSuperColumn> iterator = ks.getColumnsIterator(); while (iterator.hasNext()) { ColumnOrSuperColumn columnOrSuperColumn = iterator.next(); if (columnOrSuperColumn.column != null) { Column col = columnOrSuperColumn.column; validator = getValidatorForValue(columnFamilyDef, col.getName()); sessionState.out.printf("=> (name=%s, value=%s, timestamp=%d%s)%n", formatColumnName(keySpace, columnFamilyName, col.name), validator.getString(col.value), col.timestamp, col.isSetTtl() ? String.format(", ttl=%d", col.getTtl()) : ""); } else if (columnOrSuperColumn.super_column != null) { SuperColumn superCol = columnOrSuperColumn.super_column; sessionState.out.printf("=> (super_column=%s,", formatColumnName(keySpace, columnFamilyName, superCol.name)); for (Column col : superCol.columns) { validator = getValidatorForValue(columnFamilyDef, col.getName()); sessionState.out.printf("%n (name=%s, value=%s, timestamp=%d%s)", formatSubcolumnName(keySpace, columnFamilyName, col.name), validator.getString(col.value), col.timestamp, col.isSetTtl() ? String.format(", ttl=%d", col.getTtl()) : ""); } sessionState.out.println(")"); } else if (columnOrSuperColumn.counter_column != null) { CounterColumn col = columnOrSuperColumn.counter_column; sessionState.out.printf("=> (counter=%s, value=%s)%n", formatColumnName(keySpace, columnFamilyName, col.name), col.value); } else if (columnOrSuperColumn.counter_super_column != null) { CounterSuperColumn superCol = columnOrSuperColumn.counter_super_column; sessionState.out.printf("=> (super_column=%s,", formatColumnName(keySpace, columnFamilyName, superCol.name)); for (CounterColumn col : superCol.columns) { sessionState.out.printf("%n (counter=%s, value=%s)", formatSubcolumnName(keySpace, columnFamilyName, col.name), col.value); } sessionState.out.println(")"); } } } sessionState.out.printf("%n%d Row%s Returned.%n", slices.size(), (slices.size() > 1 ? "s" : "")); }
From source file:com.protectwise.cassandra.retrospect.deletion.RuleBasedDeletionConvictor.java
License:Apache License
/** * Returns true if value is found inside one of the ranges defined. * * @param ranges/*from www. j a v a 2 s .c o m*/ * @param value * @return */ protected <T> boolean testRule(ByteBuffer[][] ranges, ByteBuffer value, AbstractType<?> comparator) { if (value == null) { logger.warn("Null value"); return false; } for (ByteBuffer[] range : ranges) { if (logger.isTraceEnabled()) { logger.trace("Checking {} against {} to {}", comparator.getString(value), range[0] == null ? "*" : comparator.getString(range[0]), range[1] == null ? "*" : comparator.getString(range[1])); } // Null values indicate unbounded. range[0] is the lower bound inclusive, range[1] is the upper bound inclusive. // We are guaranteed both values exist before we get to this point. if ((range[0] == null || comparator.compare(range[0], value) <= 0) && (range[1] == null || comparator.compare(range[1], value) >= 0)) { return true; } } return false; }
From source file:com.tuplejump.stargate.cassandra.RowIndexSupport.java
License:Apache License
private Pair<CompositeType.Builder, StringBuilder> pkBuilder(AbstractType rowKeyComparator, ByteBuffer rowKey, CompositeType baseComparator, int prefixSize, ByteBuffer[] components) { List<AbstractType<?>> types = baseComparator.types; StringBuilder sb = new StringBuilder(); CompositeType.Builder builder = new CompositeType.Builder(baseComparator); builder.add(rowKey);//from w w w. ja v a2 s. c o m sb.append(rowKeyComparator.getString(rowKey)); for (int i = 0; i < Math.min(prefixSize, components.length); i++) { builder.add(components[i]); AbstractType<?> componentType = types.get(i); sb.append(':').append(componentType.compose(components[i])); } return Pair.create(builder, sb); }
From source file:com.tuplejump.stargate.cassandra.RowIndexSupport.java
License:Apache License
protected List<Field> collectionFields(CollectionType validator, String colName, Column column) { CompositeType baseComparator = (CompositeType) table.getComparator(); ByteBuffer[] components = baseComparator.split(column.name()); List<Field> fields = new ArrayList<>(); FieldType[] fieldTypesArr = options.collectionFieldTypes.get(colName); FieldType docValueType = options.collectionFieldDocValueTypes.get(colName); AbstractType keyType = validator.nameComparator(); AbstractType valueType = validator.valueComparator(); if (validator instanceof MapType) { ByteBuffer keyBuf = components[components.length - 1]; if (fieldTypesArr != null) { fields.add(Fields.field(colName + "._key", keyType, keyBuf, fieldTypesArr[0])); fields.add(Fields.field(colName + "._value", valueType, column.value(), fieldTypesArr[1])); fields.add(Fields.field((colName + "." + keyType.getString(keyBuf)).toLowerCase(), valueType, column.value(), fieldTypesArr[1])); }/* ww w . java 2s. c o m*/ if (docValueType != null) fields.add(Fields.field((colName + "." + keyType.getString(keyBuf)).toLowerCase(), valueType, column.value(), docValueType)); } else if (validator instanceof SetType) { if (fieldTypesArr != null) fields.add(Fields.field(colName, keyType, components[components.length - 1], fieldTypesArr[0])); if (docValueType != null) fields.add(Fields.field(colName, keyType, components[components.length - 1], docValueType)); } else if (validator instanceof ListType) { if (fieldTypesArr != null) fields.add(Fields.field(colName, valueType, column.value(), fieldTypesArr[0])); if (docValueType != null) fields.add(Fields.field(colName, valueType, column.value(), docValueType)); } else throw new UnsupportedOperationException("Unsupported collection type " + validator); return fields; }
From source file:com.tuplejump.stargate.Fields.java
License:Apache License
public static Field field(String name, AbstractType type, ByteBuffer byteBufferValue, FieldType fieldType) { if (fieldType.docValueType() != null) { if (fieldType.numericType() != null) return numericDocValuesField(name, type, byteBufferValue); else/*from w w w .j a v a 2s . co m*/ return stringDocValuesField(name, type, byteBufferValue); } CQL3Type cqlType = type.asCQL3Type(); if (cqlType == CQL3Type.Native.INT) { return new IntField(name, (Integer) type.compose(byteBufferValue), fieldType); } else if (cqlType == CQL3Type.Native.VARINT || cqlType == CQL3Type.Native.BIGINT || cqlType == CQL3Type.Native.COUNTER) { return new LongField(name, ((Number) type.compose(byteBufferValue)).longValue(), fieldType); } else if (cqlType == CQL3Type.Native.DECIMAL || cqlType == CQL3Type.Native.DOUBLE) { return new DoubleField(name, ((Number) type.compose(byteBufferValue)).doubleValue(), fieldType); } else if (cqlType == CQL3Type.Native.FLOAT) { return new FloatField(name, ((Number) type.compose(byteBufferValue)).floatValue(), fieldType); } else if (cqlType == CQL3Type.Native.ASCII || cqlType == CQL3Type.Native.TEXT || cqlType == CQL3Type.Native.VARCHAR) { return new Field(name, type.getString(byteBufferValue), fieldType); } else if (cqlType == CQL3Type.Native.UUID) { return new Field(name, type.getString(byteBufferValue), fieldType); } else if (cqlType == CQL3Type.Native.TIMEUUID) { //TimeUUID toString is not comparable. So we reorder to get a comparable value while searching return new Field(name, reorderTimeUUId(type.getString(byteBufferValue)), fieldType); } else if (cqlType == CQL3Type.Native.TIMESTAMP) { return new LongField(name, ((Date) type.compose(byteBufferValue)).getTime(), fieldType); } else if (cqlType == CQL3Type.Native.BOOLEAN) { Boolean val = ((Boolean) type.compose(byteBufferValue)); return new Field(name, val.toString(), fieldType); } else { return new Field(name, toString(byteBufferValue, type), fieldType); } }
From source file:com.tuplejump.stargate.RowIndex.java
License:Apache License
public void deleteByKey(DecoratedKey key) { readLock.lock();/*from w ww . j ava 2 s . com*/ try { AbstractType<?> rkValValidator = baseCfs.metadata.getKeyValidator(); Term term = LuceneUtils.rkTerm(rkValValidator.getString(key.key)); indexContainer.indexer(key).delete(term); } finally { readLock.unlock(); } }