/** * Returns whether this cell is encoded with Avro. * @return whether this cell is encoded with Avro. */ public boolean isAvro() { Preconditions.checkNotNull(mCellSchema); return (mCellSchema.getType() == SchemaType.INLINE) || (mCellSchema.getType() == SchemaType.CLASS) || (mCellSchema.getType() == SchemaType.AVRO); }
/** * Returns whether this cell is a counter. * @return whether this cell is a counter. */ public boolean isCounter() { Preconditions.checkNotNull(mCellSchema); return mCellSchema.getType() == SchemaType.COUNTER; }
/** * Initializes a new RawBytesCellDecoder. * * @param cellSpec Specification of the cell encoding. */ public RawBytesCellDecoder(CellSpec cellSpec) { Preconditions.checkNotNull(cellSpec); Preconditions.checkArgument( cellSpec.getCellSchema().getType() == SchemaType.RAW_BYTES); }
/** * Initializes a new RawBytesCellEncoder. * * @param cellSpec Specification of the cell to encode. * @throws IOException on I/O error. */ public RawBytesCellEncoder(final CellSpec cellSpec) throws IOException { mCellSpec = Preconditions.checkNotNull(cellSpec); Preconditions.checkArgument(cellSpec.getCellSchema().getType() == SchemaType.RAW_BYTES); }
/** * Initializes a ProtobufCellDecoder. * * @param cellSpec Specification of the cell encoding. * @throws IOException on I/O error. */ public ProtobufCellDecoder(CellSpec cellSpec) throws IOException { Preconditions.checkNotNull(cellSpec); Preconditions.checkArgument( cellSpec.getCellSchema().getType() == SchemaType.PROTOBUF); final String className = cellSpec.getCellSchema().getProtobufClassName(); try { mProtoClass = Class.forName(className).asSubclass(AbstractMessageLite.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } try { mParseFromMethod = mProtoClass.getMethod("parseFrom", byte[].class); } catch (NoSuchMethodException nsme) { throw new IOException(nsme); } }
/** * Verifies that a column is a counter. * * @param family A column family. * @param qualifier A column qualifier. * @throws IOException If the column is not a counter, or it does not exist. */ private void verifyIsCounter(String family, String qualifier) throws IOException { final FijiColumnName column = FijiColumnName.create(family, qualifier); if (mWriterLayoutCapsule.getLayout().getCellSchema(column).getType() != SchemaType.COUNTER) { throw new IOException(String.format("Column '%s' is not a counter", column)); } }
/** {@inheritDoc} */ @Override public FijiCellEncoder create(final CellSpec cellSpec) throws IOException { Preconditions.checkNotNull(cellSpec); switch (cellSpec.getCellSchema().getType()) { case INLINE: case AVRO: case CLASS: return new AvroCellEncoder(cellSpec); case COUNTER: return CounterCellEncoder.get(); case PROTOBUF: return new ProtobufCellEncoder(cellSpec); case RAW_BYTES: return new RawBytesCellEncoder(cellSpec); default: throw new RuntimeException("Unhandled cell encoding: " + cellSpec.getCellSchema().getType()); } } }
Preconditions.checkArgument(cellSpec.getCellSchema().getType() == SchemaType.PROTOBUF); mProtobufFullName = cellSpec.getCellSchema().getProtobufFullName(); Preconditions.checkNotNull(mProtobufFullName);
/** * Returns a mutable list of registered schemas (READER, WRITER, WRITTEN) of the provided column. * * <p> * The list of schemas comes from a deeply nested record within the mutable table layout * descriptor. Therefore, mutating this list effectively mutates the table layout descriptor. * </p> * * @param columnName whose schema ids to list * @param schemaRegistrationType of the schemas to list: (READER, WRITER, WRITTEN). * @return The list of schema ids. * Returns empty list if schema validation was not previously enabled. * @throws NoSuchColumnException when column not found * @throws InvalidLayoutException if the column is final or non-AVRO */ private List<AvroSchema> getMutableRegisteredSchemaList( final FijiColumnName columnName, final SchemaRegistrationType schemaRegistrationType) throws NoSuchColumnException, InvalidLayoutException { Preconditions.checkNotNull(columnName); Preconditions.checkNotNull(schemaRegistrationType); final CellSchema cellSchema = getColumnSchema(columnName); // Avoid tracking schemas final or non-AVRO cells. if ((SchemaType.AVRO != cellSchema.getType()) || (SchemaStorage.FINAL == cellSchema.getStorage())) { throw new InvalidLayoutException("Final or non-AVRO column schema cannot be modified."); } final String fieldName = schemaRegistrationType.getCellSchemaFieldName(); return (List<AvroSchema>) Preconditions.checkNotNull(cellSchema.get(fieldName)); }
: mTableImportDescriptor.getColumnNameSourceMap().keySet()) { CellSchema cellSchema = mOutputTableLayout.getCellSchema(fijiColumnName); switch(cellSchema.getType()) { case AVRO: throw new IOException("Unsupported described output type: " + cellSchema.getType()); default: throw new IOException("Unsupported described output type: " + cellSchema.getType());
if (family.getMapSchema() != null) { if (family.getMapSchema().getType() == SchemaType.COUNTER) { throw new IllegalArgumentException(String.format( "Fiji Cassandra does not support counter map type families. Family: %s, table: %s.", if (column.getColumnSchema().getType() == SchemaType.COUNTER) { throw new IllegalArgumentException(String.format( "Fiji Cassandra does not support counter columns."
/** {@inheritDoc} */ @Override public <T> FijiCellDecoder<T> create(CellSpec cellSpec) throws IOException { Preconditions.checkNotNull(cellSpec); switch (cellSpec.getCellSchema().getType()) { case AVRO: case CLASS: case INLINE: return new GenericCellDecoder<T>(cellSpec); case RAW_BYTES: return new RawBytesCellDecoder(cellSpec); case PROTOBUF: return new ProtobufCellDecoder<T>(cellSpec); case COUNTER: // purposefully forget the type (long) param of cell decoders for counters. @SuppressWarnings("unchecked") final FijiCellDecoder<T> counterCellDecoder = (FijiCellDecoder<T>) CounterCellDecoder.get(); return counterCellDecoder; default: throw new InternalFijiError("Unhandled cell encoding: " + cellSpec.getCellSchema()); } }
/** {@inheritDoc} */ @Override public <T> FijiCellDecoder<T> create(CellSpec cellSpec) throws IOException { Preconditions.checkNotNull(cellSpec); switch (cellSpec.getCellSchema().getType()) { case AVRO: case CLASS: case INLINE: return new SpecificCellDecoder<T>(cellSpec); case PROTOBUF: return new ProtobufCellDecoder<T>(cellSpec); case RAW_BYTES: return new RawBytesCellDecoder(cellSpec); case COUNTER: // purposefully forget the type (long) param of cell decoders for counters. @SuppressWarnings("unchecked") final FijiCellDecoder<T> counterCellDecoder = (FijiCellDecoder<T>) CounterCellDecoder.get(); return counterCellDecoder; default: throw new InternalFijiError("Unhandled cell encoding: " + cellSpec.getCellSchema()); } }
if (cellSchema.getType() == SchemaType.COUNTER) { if (-1 == mTimestamp) { try {
switch (mCellSchema.getType()) { case AVRO: {
if (family.getDesc().getMapSchema().getType() == SchemaType.COUNTER) { for (ColumnLayout column : entry.getValue()) { final FijiColumnName colName = FijiColumnName.create(familyName, column.getName()); if (column.getDesc().getColumnSchema().getType() == SchemaType.COUNTER) { final FijiCell<Long> counter = row.getMostRecentCell(colName.getFamily(), colName.getQualifier());
try { final CellSchema cellSchema = table.getLayout().getCellSchema(column); if (cellSchema.getType() != SchemaType.COUNTER) { LOG.error("Can't increment non counter-type column '{}'", column); return FAILURE;