private RecordSchema retrieveSchemaByName(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { final Optional<String> schemaName = schemaIdentifier.getName(); if (!schemaName.isPresent()) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Name is not present"); } return schemaNameMap.get(schemaName.get()); }
@Override public RecordSchema retrieveSchema(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { final Optional<String> schemaName = schemaIdentifier.getName(); if (schemaName.isPresent()) { return retrieveSchemaByName(schemaName.get()); } else { throw new SchemaNotFoundException("This Schema Registry only supports retrieving a schema by name."); } }
private RecordSchema retrieveSchemaByName(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { final Optional<String> schemaName = schemaIdentifier.getName(); if (!schemaName.isPresent()) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Name is not present"); } final RecordSchema schema = client.getSchema(schemaName.get()); return schema; }
@Override public RecordSchema retrieveSchema(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { if (schemaIdentifier.getName().isPresent()) { return retrieveSchemaByName(schemaIdentifier); } else { return retrieveSchemaByIdAndVersion(schemaIdentifier); } }
@Override public RecordSchema retrieveSchema(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { if (schemaIdentifier.getName().isPresent()) { return retrieveSchemaByName(schemaIdentifier); } else { return retrieveSchemaById(schemaIdentifier); } }
@Override public Map<String, String> getAttributes(final RecordSchema schema) { final Map<String,String> attributes = new HashMap<>(3); final SchemaIdentifier identifier = schema.getIdentifier(); final Optional<String> nameOption = identifier.getName(); if (nameOption.isPresent()) { attributes.put(SCHEMA_NAME_ATTRIBUTE, nameOption.get()); } final OptionalInt versionOption = identifier.getVersion(); if (versionOption.isPresent()) { attributes.put(SCHEMA_VERSION_ATTRIBUTE, String.valueOf(versionOption.getAsInt())); } final Optional<String> branchOption = identifier.getBranch(); if (branchOption.isPresent()) { attributes.put(SCHEMA_BRANCH_ATTRIBUTE, branchOption.get()); } return attributes; }
@Override public void validateSchema(final RecordSchema schema) throws SchemaNotFoundException { final SchemaIdentifier schemaId = schema.getIdentifier(); if (schemaId == null) { throw new SchemaNotFoundException("Cannot write Schema Name As Attribute because Schema Identifier is not known"); } if (!schemaId.getName().isPresent()) { throw new SchemaNotFoundException("Cannot write Schema Name As Attribute because the Schema Name is not known"); } }
this.recordTagName = recordTagName; } else { Optional<String> recordTagNameOptional = recordSchema.getSchemaName().isPresent()? recordSchema.getSchemaName() : recordSchema.getIdentifier().getName(); if (recordTagNameOptional.isPresent()) { this.recordTagName = recordTagNameOptional.get();
@Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } if (!(obj instanceof SchemaIdentifier)) { return false; } final SchemaIdentifier other = (SchemaIdentifier) obj; return getName().equals(other.getName()) && getIdentifier().equals(other.getIdentifier()) && getVersion().equals(other.getVersion()) && getBranch().equals(other.getBranch()); }
final Long schemaId; final Optional<String> schemaName = schemaIdentifier.getName(); if (!schemaName.isPresent()) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Name is not present");
@Override public HDFSRecordWriter createHDFSRecordWriter(final ProcessContext context, final FlowFile flowFile, final Configuration conf, final Path path, final RecordSchema schema) throws IOException, SchemaNotFoundException { final long stripeSize = context.getProperty(STRIPE_SIZE).asDataSize(DataUnit.B).longValue(); final int bufferSize = context.getProperty(BUFFER_SIZE).asDataSize(DataUnit.B).intValue(); final CompressionKind compressionType = CompressionKind.valueOf(context.getProperty(COMPRESSION_TYPE).getValue()); final boolean normalizeForHive = context.getProperty(HIVE_FIELD_NAMES).asBoolean(); TypeInfo orcSchema = NiFiOrcUtils.getOrcSchema(schema, normalizeForHive); final Writer orcWriter = NiFiOrcUtils.createWriter(path, conf, orcSchema, stripeSize, compressionType, bufferSize); final String hiveTableName = context.getProperty(HIVE_TABLE_NAME).isSet() ? context.getProperty(HIVE_TABLE_NAME).evaluateAttributeExpressions(flowFile).getValue() : NiFiOrcUtils.normalizeHiveTableName(schema.getIdentifier().getName().orElse("unknown")); final boolean hiveFieldNames = context.getProperty(HIVE_FIELD_NAMES).asBoolean(); return new ORCHDFSRecordWriter(orcWriter, schema, hiveTableName, hiveFieldNames); } }
private RecordSchema retrieveSchemaByName(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { final Optional<String> schemaName = schemaIdentifier.getName(); if (!schemaName.isPresent()) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Name is not present"); } final RecordSchema schema = client.getSchema(schemaName.get()); return schema; }
@Override public Map<String, String> getAttributes(final RecordSchema schema) { final Map<String,String> attributes = new HashMap<>(3); final SchemaIdentifier identifier = schema.getIdentifier(); final Optional<String> nameOption = identifier.getName(); if (nameOption.isPresent()) { attributes.put(SCHEMA_NAME_ATTRIBUTE, nameOption.get()); } final OptionalInt versionOption = identifier.getVersion(); if (versionOption.isPresent()) { attributes.put(SCHEMA_VERSION_ATTRIBUTE, String.valueOf(versionOption.getAsInt())); } final Optional<String> branchOption = identifier.getBranch(); if (branchOption.isPresent()) { attributes.put(SCHEMA_BRANCH_ATTRIBUTE, branchOption.get()); } return attributes; }
@Override public RecordSchema retrieveSchema(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { if (schemaIdentifier.getName().isPresent()) { return retrieveSchemaByName(schemaIdentifier); } else { return retrieveSchemaById(schemaIdentifier); } }
@Override public void validateSchema(final RecordSchema schema) throws SchemaNotFoundException { final SchemaIdentifier schemaId = schema.getIdentifier(); if (schemaId == null) { throw new SchemaNotFoundException("Cannot write Schema Name As Attribute because Schema Identifier is not known"); } if (!schemaId.getName().isPresent()) { throw new SchemaNotFoundException("Cannot write Schema Name As Attribute because the Schema Name is not known"); } }
@Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } if (!(obj instanceof SchemaIdentifier)) { return false; } final SchemaIdentifier other = (SchemaIdentifier) obj; return getName().equals(other.getName()) && getIdentifier().equals(other.getIdentifier()) && getVersion().equals(other.getVersion()) && getBranch().equals(other.getBranch()); }