/** {@inheritDoc} */ @Deprecated @Override public FijiTableLayout modifyTableLayout(String tableName, TableLayoutDesc update) throws IOException { if (!tableName.equals(update.getName())) { throw new InvalidLayoutException(String.format( "Name of table in descriptor '%s' does not match table name '%s'.", update.getName(), tableName)); } return modifyTableLayout(update); }
/** {@inheritDoc} */ @Deprecated @Override public FijiTableLayout modifyTableLayout(String tableName, TableLayoutDesc update) throws IOException { if (!tableName.equals(update.getName())) { throw new InvalidLayoutException(String.format( "Name of table in descriptor '%s' does not match table name '%s'.", update.getName(), tableName)); } return modifyTableLayout(update); }
/** * Configures this column to decode cells using Avro specific records. * * <p> For Avro-encoded cells only. </p> * * @param klass Avro generated class of the specific record to decode this column to. * @return this CellSpec. * @throws InvalidLayoutException if the specified class is not a valid Avro specific record. */ public CellSpec setSpecificRecord(final Class<? extends SpecificRecord> klass) throws InvalidLayoutException { try { final java.lang.reflect.Field field = klass.getField("SCHEMA$"); final Schema schema = (Schema) field.get(klass); if (!klass.getName().equals(schema.getFullName())) { throw new InvalidLayoutException(String.format( "Specific record class name '%s' does not match schema name '%s'.", klass.getName(), schema.getFullName())); } return setReaderSchema(schema) .setDecoderFactory(SpecificCellDecoderFactory.get()); } catch (IllegalAccessException iae) { throw new InvalidLayoutException(String.format( "Invalid specific record class '%s': %s", klass.getName(), iae.getMessage())); } catch (NoSuchFieldException nsfe) { throw new InvalidLayoutException(String.format( "Invalid specific record class '%s': %s", klass.getName(), nsfe.getMessage())); } }
/** * Ensure a row key format (version 1) specified in a layout file is sane. * @param format The RowKeyFormat created from the layout file for a table. * @throws InvalidLayoutException If the format is invalid. */ private void isValidRowKeyFormat1(RowKeyFormat format) throws InvalidLayoutException { RowKeyEncoding rowKeyEncoding = format.getEncoding(); if (rowKeyEncoding != RowKeyEncoding.RAW && rowKeyEncoding != RowKeyEncoding.HASH && rowKeyEncoding != RowKeyEncoding.HASH_PREFIX) { throw new InvalidLayoutException("RowKeyFormat only supports encodings" + "of type RAW, HASH and HASH_PREFIX. Use RowKeyFormat2 instead"); } if (rowKeyEncoding == RowKeyEncoding.HASH || rowKeyEncoding == RowKeyEncoding.HASH_PREFIX) { if (format.getHashSize() < 0 || format.getHashSize() > Hasher.HASH_SIZE_BYTES) { throw new InvalidLayoutException("HASH or HASH_PREFIX row key formats require hash size" + "to be between 1 and " + Hasher.HASH_SIZE_BYTES); } } }
/** {@inheritDoc} */ @Deprecated @Override public FijiTableLayout modifyTableLayout( String tableName, TableLayoutDesc update, boolean dryRun, PrintStream printStream) throws IOException { if (!tableName.equals(update.getName())) { throw new InvalidLayoutException(String.format( "Name of table in descriptor '%s' does not match table name '%s'.", update.getName(), tableName)); } return modifyTableLayout(update, dryRun, printStream); }
/** {@inheritDoc} */ @Deprecated @Override public FijiTableLayout modifyTableLayout( String tableName, TableLayoutDesc update, boolean dryRun, PrintStream printStream) throws IOException { if (!tableName.equals(update.getName())) { throw new InvalidLayoutException(String.format( "Name of table in descriptor '%s' does not match table name '%s'.", update.getName(), tableName)); } return modifyTableLayout(update, dryRun, printStream); }
/** * Reports the Avro schema from a generated class. * * @param klass Generated class to report the schema of. * @return Avro schema of the specified generated class. * @throws InvalidLayoutException if the specified class does not correspond to a valid Avro type. */ public static Schema getSchemaFromClass(Class<? extends SpecificRecord> klass) throws InvalidLayoutException { try { return SpecificData.get().getSchema(klass); } catch (RuntimeException re) { LOG.debug("Error accessing schema from Avro class: {}", StringUtils.stringifyException(re)); throw new InvalidLayoutException("Java class is not a valid Avro type: " + klass.getName()); } }
/** * Reports the Avro schema from a generated class. * * @param className Fully-qualified name of the generated class to report the schema of. * @return Avro schema of the specified generated class. * @throws InvalidLayoutException if the specified class does not correspond to a valid Avro type. * In particular, throws {@link SchemaClassNotFoundException} if the class cannot be found. */ public static Schema getSchemaFromClass(String className) throws InvalidLayoutException { if (!JavaIdentifiers.isValidClassName(className)) { throw new InvalidLayoutException(String.format( "Invalid cell specification with Avro class type has invalid class name: '%s'.", className)); } try { final Class<? extends SpecificRecord> avroClass = Class.forName(className).asSubclass(SpecificRecord.class); return getSchemaFromClass(avroClass); } catch (ClassNotFoundException cnfe) { throw new SchemaClassNotFoundException( "Java class " + className + " was not found on the classpath."); } }
return new Schema.Parser().parse(cellSchema.getValue()); } catch (RuntimeException re) { throw new InvalidLayoutException(String.format( "Invalid Avro schema: '%s' caused error: %s.", cellSchema.getValue(), re.getMessage())); throw new InvalidLayoutException("Invalid schema type: " + cellSchema.getType());
/** * 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)); }
throw new InvalidLayoutException("RowKeyFormat2 only supports RAW or FORMATTED encoding." + "Found " + format.getEncoding().name()); throw new InvalidLayoutException("At least 1 component is required in row key format."); throw new InvalidLayoutException( "Null values for RowKeyFormat2.salt are only allowed for RAW encoding."); throw new InvalidLayoutException("Invalid index for nullable component. The second component" + " onwards can be set to null."); throw new InvalidLayoutException("Invalid range scan index. Range scans are supported " + "starting with the second component."); throw new InvalidLayoutException("Range scans are not supported if " + "suppress_key_materialization is true. Please set range_scan_start_index " + "to components.size"); throw new InvalidLayoutException("Names should begin with a letter followed by a " + "combination of letters, numbers and underscores."); throw new InvalidLayoutException("Component name already used."); throw new InvalidLayoutException("Valid hash sizes are between 1 and " + Hasher.HASH_SIZE_BYTES);
case AVRO: { if (layoutVersion.compareTo(Versions.LAYOUT_VALIDATION_VERSION) < 0) { throw new InvalidLayoutException(String.format( "Cell type %s requires table layout version >= %s, " + "got version %s in cell specification %s.", throw new InvalidLayoutException(String.format( "Cell type %s requires table layout version >= %s, " + "got version %s in cell specification %s.", throw new InvalidLayoutException(String.format( "Cell type %s requires table layout version >= %s, " + "got version %s in cell specification %s.", break; default: throw new InvalidLayoutException(String.format( "Invalid final column schema: %s.", schema)); throw new InvalidLayoutException(String.format( "Invalid counter schema, storage must be final: %s.", schema)); throw new InvalidLayoutException(String.format( "Cell schema storage cannot be modified from %s to %s.", reference, schema)); throw new InvalidLayoutException(String.format( "Final column schema cannot be modified from %s to %s.", reference, schema));
throw new InvalidLayoutException(tableLayout, String.format("Layout ID '%s' already exists", layoutId));
throw new InvalidLayoutException(String.format( "Invalid column name: '%s'.", desc.getName())); throw new InvalidLayoutException(String.format( "Invalid column alias: '%s'.", name)); throw new InvalidLayoutException(String.format( "Descriptor for column '%s' has ID %s but reference ID is %s.", getName(), mId, reference.getId()));
throw new InvalidLayoutException(tableLayout, String.format("Layout ID '%s' already exists", layoutId));
throw new InvalidLayoutException(String.format( "Invalid locality group name: '%s'.", lgDesc.getName())); throw new InvalidLayoutException(String.format( "Invalid locality group alias: '%s'.", name)); throw new InvalidLayoutException(String.format( "Invalid TTL seconds for locality group '%s': TTL must be positive, got %d.", getName(), mDesc.getTtlSeconds())); throw new InvalidLayoutException(String.format( "Invalid max versions for locality group '%s': max versions must be positive, got %d.", getName(), mDesc.getMaxVersions())); throw new InvalidLayoutException(String.format( "Descriptor for locality group '%s' has ID %s but reference ID is %s.", getName(), mId, reference.getId())); familyDesc.setRenamedFrom(null); if (isRename && (reference == null)) { throw new InvalidLayoutException(String.format( "Invalid rename: no reference locality group '%s' for family '%s'.", getName(), refFName)); (reference != null) ? reference.getFamilyMap().get(refFName) : null; if (isRename && (refFLayout == null)) { throw new InvalidLayoutException(String.format( "Invalid rename: cannot find reference family '%s' in locality group '%s'.", refFName, getName()));
throw new InvalidLayoutException(String.format( "Invalid family '%s' with both map-type and columns", getName())); throw new InvalidLayoutException(String.format( "Invalid family name: '%s'.", familyDesc.getName())); throw new InvalidLayoutException(String.format( "Invalid family alias: '%s'.", name)); throw new InvalidLayoutException(String.format( "Descriptor for family '%s' has ID %s but reference ID is %s.", getName(), mId, reference.getId())); throw new InvalidLayoutException(String.format( "Invalid layout update for family '%s' from reference type %s to type %s.", getName(), columnDesc.setRenamedFrom(null); if (isRename && (reference == null)) { throw new InvalidLayoutException(String.format( "Invalid renaming: cannot find reference family for column '%s:%s'.", getName(), refCName)); (reference != null) ? reference.getColumnMap().get(refCName) : null; if (isRename && (refCLayout == null)) { throw new InvalidLayoutException(String.format( "Invalid renaming: cannot find column '%s:%s' in reference family.", getName(), refCName));
final Schema schemaFromId = mSchemaTable.getSchema(avroSchema.getUid()); if (!Objects.equal(schema, schemaFromId)) { throw new InvalidLayoutException(String.format( "Inconsistent AvroSchema: '%s' : UID %d does not match with JSON descriptor '%s'.", avroSchema, avroSchema.getUid(), avroSchema.getJson())); throw new InvalidLayoutException("AvroSchema has neither JSON nor UID: " + avroSchema);
throw new InvalidLayoutException( String.format("Layout version: %s not supported by system version: %s", layoutVersion, systemVersion));
mReaderSchema = new Schema.Parser().parse(cellSchema.getValue()); } catch (RuntimeException re) { throw new InvalidLayoutException(String.format( "Invalid Avro schema '%s' caused error: %s.", cellSchema.getValue(), re.getMessage()));