/** * Reports the cell format for the specified column. * * @param column Column name. * @return the cell format for the column. * @throws NoSuchColumnException if the column does not exist. * @deprecated Use {@link #getCellSpec(FijiColumnName)} to obtain further details about a column. */ @Deprecated public SchemaStorage getCellFormat(FijiColumnName column) throws NoSuchColumnException { return getCellSchema(column).getStorage(); }
/** * Reports the Avro schema of the specified column. * * <p> This method will return null in most cases on table with layout validation enabled. </p> * * @param columnName Column name. * @return the Avro schema of the column. * @throws InvalidLayoutException if the layout is invalid. * @throws NoSuchColumnException if the column does not exist. * @deprecated With schema validation and layout 1.3, there is no single Avro schema associated * with a column anymore. * Use {@link #getCellSpec(FijiColumnName)} to obtain further details about a column. */ @Deprecated public Schema getSchema(FijiColumnName columnName) throws InvalidLayoutException, NoSuchColumnException { return CellSpec.readAvroSchema(getCellSchema(columnName)); }
/** * Reports the specification of the specified column. * * @param column Column to report the specification of. * @return the specification for the specified column. * @throws IOException on I/O error. */ public CellSpec getCellSpec(FijiColumnName column) throws IOException { return CellSpec.fromCellSchema(getCellSchema(column)) .setSchemaTable(mSchemaTable); }
/** * 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)); } }
/** * Get the Avro Schema for a given column marked FINAL in a given layout. This will either be * defined INLINE as a Schema JSON or it will be the only writer schema in the layout 1.3+ * Avro writers field. * * @param layout table layout from which to get the Schema for the given column. * @param column column for which to get the Schema. * @return Avro Schema of the given column. * @throws NoSuchColumnException in case the column does not exist. */ private static Schema getSchemaForFinalColumn(FijiTableLayout layout, FijiColumnName column) throws NoSuchColumnException { final List<AvroSchema> writers = layout.getCellSchema(column).getWriters(); if (null == writers) { return new Schema.Parser().parse(layout.getCellSchema(column).getValue()); } else { Preconditions.checkState(writers.size() == 1, "FINAL columns must have exactly one writer schema, found: " + writers); return new SchemaTableAvroResolver(layout.getSchemaTable()).apply(writers.get(0)); } }
/** * Initializes a ProtobufCellDecoder. * * @param layout FijiTableLayout from which to get the Protobuf class name. * @param spec Specification of the cell encoding. * @throws IOException on I/O error. */ public ProtobufCellDecoder(FijiTableLayout layout, BoundColumnReaderSpec spec) throws IOException { Preconditions.checkNotNull(layout); Preconditions.checkNotNull(spec); Preconditions.checkArgument( spec.getColumnReaderSpec().getEncoding() == Encoding.PROTOBUF); final String className = layout.getCellSchema(spec.getColumn()).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); } }
/** * Builds the Hive type from the schema for a particular cell within Hive. * * @param fijiColumnName that specifices which column to build the Hive type from. * @param fijiTableLayout where the column resides. * @param schemaTable of the Fiji instance for type mappings * @return String representing the corresponding Hive type for a cell within the table's layout. * @throws IOException if there is an issue retrieving the schema of a particular column. */ protected static String getHiveType(FijiColumnName fijiColumnName, FijiTableLayout fijiTableLayout, FijiSchemaTable schemaTable) throws IOException { CellSchema cellSchema = fijiTableLayout.getCellSchema(fijiColumnName); Schema schema = getSchemaFromCellSchema(cellSchema, schemaTable); String hiveType = ""; if (null != schema) { hiveType = convertSchemaToHiveType(schema); if (!fijiColumnName.isFullyQualified()) { hiveType = "MAP<STRING, " + hiveType + ">"; } } else { // Null schemas are probably indicative of a counter, but they are currently unsupported // within the Fiji Hive Adapter. Log a warning, and let the user fix it. LOG.warn(fijiColumnName.toString() + " has a null schema and is unsupported within Hive."); } return hiveType; }
if (SchemaType.COUNTER == fijiTable.getLayout().getCellSchema(column).getType()) { JsonNode parsedCounterValue = BASIC_MAPPER.valueToTree(restCell.getValue()); if (parsedCounterValue.isIntegralNumber()) {
for (FijiColumnName fijiColumnName : mTableImportDescriptor.getColumnNameSourceMap().keySet()) { CellSchema cellSchema = mOutputTableLayout.getCellSchema(fijiColumnName); switch(cellSchema.getType()) { case AVRO:
final FijiColumnName column = mColumnURI.getColumns().get(0); final FijiTableLayout layout = mTable.getLayout(); final CellSchema cellSchema = layout.getCellSchema(column);
for (FijiColumnName column : mCellURI.getColumns()) { try { final CellSchema cellSchema = table.getLayout().getCellSchema(column); if (cellSchema.getType() != SchemaType.COUNTER) { LOG.error("Can't increment non counter-type column '{}'", column);
/** * Get the Avro Schema to use to decode cells. * * @param layout FijiTableLayout from which to get storage information. * @param spec Specification of the cell encoding. * @return the Avro Schema to use to decode cells. * @throws IOException in case the specified column does not exist. */ private static Schema getReaderSchema(FijiTableLayout layout, BoundColumnReaderSpec spec) throws IOException { switch (spec.getColumnReaderSpec().getAvroReaderSchemaType()) { case DEFAULT: { final CellSchema cellSchema = layout.getCellSchema(spec.getColumn()); final SchemaTableAvroResolver resolver = new SchemaTableAvroResolver(layout.getSchemaTable()); return resolver.apply(cellSchema.getDefaultReader()); } case EXPLICIT: return spec.getColumnReaderSpec().getAvroReaderSchema(); case WRITER: return null; default: throw new InternalFijiError( "Unknown AvroReaderSchemaType: " + spec.getColumnReaderSpec().getAvroReaderSchemaType()); } }
final CellSchema cellSchema = layout.getCellSchema(spec.getColumn());