http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/record/MockRecordWriter.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/record/MockRecordWriter.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/record/MockRecordWriter.java deleted file mode 100644 index ca16bcd..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/record/MockRecordWriter.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.processors.standard.util.record; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Collections; - -import org.apache.nifi.controller.AbstractControllerService; -import org.apache.nifi.flowfile.FlowFile; -import org.apache.nifi.logging.ComponentLog; -import org.apache.nifi.serialization.RecordSetWriter; -import org.apache.nifi.serialization.RecordSetWriterFactory; -import org.apache.nifi.serialization.WriteResult; -import org.apache.nifi.serialization.record.Record; -import org.apache.nifi.serialization.record.RecordSet; - -public class MockRecordWriter extends AbstractControllerService implements RecordSetWriterFactory { - private final String header; - private final int failAfterN; - private final boolean quoteValues; - - public MockRecordWriter(final String header) { - this(header, true, -1); - } - - public MockRecordWriter(final String header, final boolean quoteValues) { - this(header, quoteValues, -1); - } - - public MockRecordWriter(final String header, final boolean quoteValues, final int failAfterN) { - this.header = header; - this.quoteValues = quoteValues; - this.failAfterN = failAfterN; - } - - @Override - public RecordSetWriter createWriter(final ComponentLog logger, final FlowFile flowFile, final InputStream in) { - return new RecordSetWriter() { - @Override - public WriteResult write(final RecordSet rs, final OutputStream out) throws IOException { - out.write(header.getBytes()); - out.write("\n".getBytes()); - - int recordCount = 0; - final int numCols = rs.getSchema().getFieldCount(); - Record record = null; - while ((record = rs.next()) != null) { - if (++recordCount > failAfterN && failAfterN > -1) { - throw new IOException("Unit Test intentionally throwing IOException after " + failAfterN + " records were written"); - } - - int i = 0; - for (final String fieldName : record.getSchema().getFieldNames()) { - final String val = record.getAsString(fieldName); - if (quoteValues) { - out.write("\"".getBytes()); - if (val != null) { - out.write(val.getBytes()); - } - out.write("\"".getBytes()); - } else if (val != null) { - out.write(val.getBytes()); - } - - if (i++ < numCols - 1) { - out.write(",".getBytes()); - } - } - out.write("\n".getBytes()); - } - - return WriteResult.of(recordCount, Collections.emptyMap()); - } - - @Override - public String getMimeType() { - return "text/plain"; - } - - @Override - public WriteResult write(Record record, OutputStream out) throws IOException { - out.write(header.getBytes()); - out.write("\n".getBytes()); - - final int numCols = record.getSchema().getFieldCount(); - int i = 0; - for (final String fieldName : record.getSchema().getFieldNames()) { - final String val = record.getAsString(fieldName); - if (quoteValues) { - out.write("\"".getBytes()); - out.write(val.getBytes()); - out.write("\"".getBytes()); - } else { - out.write(val.getBytes()); - } - - if (i++ < numCols - 1) { - out.write(",".getBytes()); - } - } - out.write("\n".getBytes()); - - return WriteResult.of(1, Collections.emptyMap()); - } - }; - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml b/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml index cd722cf..3b2ea39 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml +++ b/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml @@ -44,12 +44,6 @@ <dependency> <groupId>org.apache.nifi</groupId> <artifactId>nifi-hadoop-utils</artifactId> - <exclusions> - <exclusion> - <groupId>org.apache.hadoop</groupId> - <artifactId>hadoop-common</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>org.apache.hbase</groupId> http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-hwx-schema-registry-bundle/nifi-hwx-schema-registry-service/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-hwx-schema-registry-bundle/nifi-hwx-schema-registry-service/pom.xml b/nifi-nar-bundles/nifi-standard-services/nifi-hwx-schema-registry-bundle/nifi-hwx-schema-registry-service/pom.xml index b17f93b..d740067 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-hwx-schema-registry-bundle/nifi-hwx-schema-registry-service/pom.xml +++ b/nifi-nar-bundles/nifi-standard-services/nifi-hwx-schema-registry-bundle/nifi-hwx-schema-registry-service/pom.xml @@ -38,12 +38,14 @@ limitations under the License. <groupId>org.apache.nifi</groupId> <artifactId>nifi-utils</artifactId> </dependency> - + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-record</artifactId> + </dependency> <dependency> <groupId>org.apache.nifi</groupId> <artifactId>nifi-schema-registry-service-api</artifactId> </dependency> - <dependency> <groupId>org.apache.avro</groupId> <artifactId>avro</artifactId> http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/pom.xml b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/pom.xml index 78c0381..9594467 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/pom.xml +++ b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/pom.xml @@ -22,10 +22,15 @@ <artifactId>nifi-record-serialization-service-api</artifactId> <packaging>jar</packaging> + <dependencies> <dependency> <groupId>org.apache.nifi</groupId> <artifactId>nifi-api</artifactId> </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-record</artifactId> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/schema/access/SchemaField.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/schema/access/SchemaField.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/schema/access/SchemaField.java deleted file mode 100644 index 2fe06f4..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/schema/access/SchemaField.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.schema.access; - -public enum SchemaField { - SCHEMA_TEXT("Schema Text"), - SCHEMA_TEXT_FORMAT("Schema Text Format"), - SCHEMA_NAME("Schema Name"), - SCHEMA_IDENTIFIER("Schema Identifier"), - SCHEMA_VERSION("Schema Version"); - - private final String description; - - private SchemaField(final String description) { - this.description = description; - } - - @Override - public String toString() { - return description; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/schema/access/SchemaNotFoundException.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/schema/access/SchemaNotFoundException.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/schema/access/SchemaNotFoundException.java deleted file mode 100644 index 9a064ff..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/schema/access/SchemaNotFoundException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.schema.access; - -public class SchemaNotFoundException extends Exception { - public SchemaNotFoundException(final String message) { - super(message); - } - - public SchemaNotFoundException(final String message, final Throwable cause) { - super(cause); - } - - public SchemaNotFoundException(final Throwable cause) { - super(cause); - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/DataTypeValidator.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/DataTypeValidator.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/DataTypeValidator.java deleted file mode 100644 index 5a71086..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/DataTypeValidator.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.apache.nifi.components.ValidationContext; -import org.apache.nifi.components.ValidationResult; -import org.apache.nifi.components.Validator; - -public class DataTypeValidator implements Validator { - private static final Set<String> validValues; - private static final Set<String> allowsFormatting; - - static { - final Set<String> values = new HashSet<>(); - values.add("string"); - values.add("boolean"); - values.add("byte"); - values.add("char"); - values.add("int"); - values.add("long"); - values.add("float"); - values.add("double"); - values.add("time"); - values.add("date"); - values.add("timestamp"); - validValues = Collections.unmodifiableSet(values); - - final Set<String> formattable = new HashSet<>(); - formattable.add("date"); - formattable.add("time"); - formattable.add("timestmap"); - allowsFormatting = Collections.unmodifiableSet(formattable); - } - - @Override - public ValidationResult validate(final String subject, final String input, final ValidationContext context) { - final String[] splits = input.split("\\:"); - - final boolean valid; - if (splits.length == 2) { - final String type = splits[0].trim(); - if (validValues.contains(type)) { - if (allowsFormatting.contains(splits[0].trim())) { - valid = true; - } else { - valid = false; - } - } else { - valid = false; - } - } else { - valid = validValues.contains(input.trim()); - } - - return new ValidationResult.Builder() - .subject(subject) - .input(input) - .valid(valid) - .explanation("Valid values for this property are: " + validValues - + ", where date, time, and timestamp may optionally contain a format (e.g., date:MM-dd-yyyy)") - .build(); - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/MalformedRecordException.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/MalformedRecordException.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/MalformedRecordException.java deleted file mode 100644 index d45a850..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/MalformedRecordException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization; - -/** - * An Exception that can be thrown to indicate that data was read but could not properly be parsed - */ -public class MalformedRecordException extends Exception { - public MalformedRecordException(final String message) { - super(message); - } - - public MalformedRecordException(final String message, final Throwable cause) { - super(message, cause); - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordReader.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordReader.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordReader.java deleted file mode 100644 index add248e..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordReader.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization; - -import java.io.Closeable; -import java.io.IOException; - -import org.apache.nifi.serialization.record.Record; -import org.apache.nifi.serialization.record.RecordSchema; -import org.apache.nifi.serialization.record.RecordSet; - -/** - * <p> - * A RowRecordReader is responsible for parsing data and returning a record at a time - * in order to allow the caller to iterate over the records individually. - * </p> - * - * <p> - * PLEASE NOTE: This interface is still considered 'unstable' and may change in a non-backward-compatible - * manner between minor or incremental releases of NiFi. - * </p> - */ -public interface RecordReader extends Closeable { - - /** - * Returns the next record in the stream or <code>null</code> if no more records are available. - * - * @return the next record in the stream or <code>null</code> if no more records are available. - * - * @throws IOException if unable to read from the underlying data - * @throws MalformedRecordException if an unrecoverable failure occurs when trying to parse a record - */ - Record nextRecord() throws IOException, MalformedRecordException; - - /** - * @return a RecordSchema that is appropriate for the records in the stream - * @throws MalformedRecordException if an unrecoverable failure occurs when trying to parse the underlying data - */ - RecordSchema getSchema() throws MalformedRecordException; - - /** - * @return a RecordSet that returns the records in this Record Reader in a streaming fashion - */ - default RecordSet createRecordSet() { - return new RecordSet() { - @Override - public RecordSchema getSchema() throws IOException { - try { - return RecordReader.this.getSchema(); - } catch (final MalformedRecordException mre) { - throw new IOException(mre); - } - } - - @Override - public Record next() throws IOException { - try { - return RecordReader.this.nextRecord(); - } catch (final MalformedRecordException mre) { - throw new IOException(mre); - } - } - }; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordSetWriter.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordSetWriter.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordSetWriter.java deleted file mode 100644 index 7d6fa1c..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordSetWriter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.nifi.serialization.record.RecordSet; - -/** - * <p> - * A ResultSetWriter is responsible for writing a ResultSet to a given {@link OutputStream}. - * </p> - * - * <p> - * PLEASE NOTE: This interface is still considered 'unstable' and may change in a non-backward-compatible - * manner between minor or incremental releases of NiFi. - * </p> - */ -public interface RecordSetWriter extends RecordWriter { - /** - * Writes the given result set to the given output stream - * - * @param recordSet the record set to serialize - * @param out the OutputStream to write to - * @return the results of writing the data - * @throws IOException if unable to write to the given OutputStream - */ - WriteResult write(RecordSet recordSet, OutputStream out) throws IOException; -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordWriter.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordWriter.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordWriter.java deleted file mode 100644 index aa298d9..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/RecordWriter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.nifi.serialization.record.Record; - -public interface RecordWriter { - /** - * Writes the given result set to the given output stream - * - * @param record the record set to serialize - * @param out the OutputStream to write to - * @return the results of writing the data - * @throws IOException if unable to write to the given OutputStream - */ - WriteResult write(Record record, OutputStream out) throws IOException; - - /** - * @return the MIME Type that the Result Set Writer produces. This will be added to FlowFiles using - * the mime.type attribute. - */ - String getMimeType(); -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/SimpleRecordSchema.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/SimpleRecordSchema.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/SimpleRecordSchema.java deleted file mode 100644 index 017aef1..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/SimpleRecordSchema.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.OptionalInt; -import java.util.stream.Collectors; - -import org.apache.nifi.serialization.record.DataType; -import org.apache.nifi.serialization.record.RecordField; -import org.apache.nifi.serialization.record.RecordSchema; -import org.apache.nifi.serialization.record.SchemaIdentifier; - -public class SimpleRecordSchema implements RecordSchema { - private final List<RecordField> fields; - private final Map<String, Integer> fieldIndices; - private final boolean textAvailable; - private final String text; - private final String schemaFormat; - private final SchemaIdentifier schemaIdentifier; - - public SimpleRecordSchema(final List<RecordField> fields) { - this(fields, createText(fields), null, false, SchemaIdentifier.EMPTY); - } - - public SimpleRecordSchema(final List<RecordField> fields, final SchemaIdentifier id) { - this(fields, createText(fields), null, false, id); - } - - public SimpleRecordSchema(final List<RecordField> fields, final String text, final String schemaFormat, final SchemaIdentifier id) { - this(fields, text, schemaFormat, true, id); - } - - private SimpleRecordSchema(final List<RecordField> fields, final String text, final String schemaFormat, final boolean textAvailable, final SchemaIdentifier id) { - this.text = text; - this.schemaFormat = schemaFormat; - this.schemaIdentifier = id; - this.textAvailable = textAvailable; - this.fields = Collections.unmodifiableList(new ArrayList<>(fields)); - this.fieldIndices = new HashMap<>(fields.size()); - - int index = 0; - for (final RecordField field : fields) { - Integer previousValue = fieldIndices.put(field.getFieldName(), index); - if (previousValue != null) { - throw new IllegalArgumentException("Two fields are given with the same name (or alias) of '" + field.getFieldName() + "'"); - } - - for (final String alias : field.getAliases()) { - previousValue = fieldIndices.put(alias, index); - if (previousValue != null) { - throw new IllegalArgumentException("Two fields are given with the same name (or alias) of '" + field.getFieldName() + "'"); - } - } - - index++; - } - } - - @Override - public Optional<String> getSchemaText() { - if (textAvailable) { - return Optional.ofNullable(text); - } else { - return Optional.empty(); - } - } - - - @Override - public Optional<String> getSchemaFormat() { - return Optional.ofNullable(schemaFormat); - } - - @Override - public List<RecordField> getFields() { - return fields; - } - - @Override - public int getFieldCount() { - return fields.size(); - } - - @Override - public RecordField getField(final int index) { - return fields.get(index); - } - - @Override - public List<DataType> getDataTypes() { - return getFields().stream().map(recordField -> recordField.getDataType()) - .collect(Collectors.toList()); - } - - @Override - public List<String> getFieldNames() { - return getFields().stream().map(recordField -> recordField.getFieldName()) - .collect(Collectors.toList()); - } - - @Override - public Optional<DataType> getDataType(final String fieldName) { - final OptionalInt idx = getFieldIndex(fieldName); - return idx.isPresent() ? Optional.of(fields.get(idx.getAsInt()).getDataType()) : Optional.empty(); - } - - @Override - public Optional<RecordField> getField(final String fieldName) { - final OptionalInt indexOption = getFieldIndex(fieldName); - if (indexOption.isPresent()) { - return Optional.of(fields.get(indexOption.getAsInt())); - } - - return Optional.empty(); - } - - private OptionalInt getFieldIndex(final String fieldName) { - final Integer index = fieldIndices.get(fieldName); - return index == null ? OptionalInt.empty() : OptionalInt.of(index); - } - - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (!(obj instanceof RecordSchema)) { - return false; - } - - final RecordSchema other = (RecordSchema) obj; - return fields.equals(other.getFields()); - } - - @Override - public int hashCode() { - return 143 + 3 * fields.hashCode(); - } - - private static String createText(final List<RecordField> fields) { - final StringBuilder sb = new StringBuilder("["); - - for (int i = 0; i < fields.size(); i++) { - final RecordField field = fields.get(i); - - sb.append("\""); - sb.append(field.getFieldName()); - sb.append("\" : \""); - sb.append(field.getDataType()); - sb.append("\""); - - if (i < fields.size() - 1) { - sb.append(", "); - } - } - sb.append("]"); - return sb.toString(); - } - - @Override - public String toString() { - return text; - } - - @Override - public SchemaIdentifier getIdentifier() { - return schemaIdentifier; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/WriteResult.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/WriteResult.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/WriteResult.java deleted file mode 100644 index 3fb2741..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/WriteResult.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization; - -import java.util.Collections; -import java.util.Map; - -/** - * <p> - * Provides information about what was written to an OutputStream by a {@link RecordSetWriter}. - * Instances of WriteResult are typically instantiated by calling the static method {@link WriteResult#of(int, Map)} - * or using {@link WriteResult#EMPTY}. - * </p> - * - * <p> - * PLEASE NOTE: This interface is still considered 'unstable' and may change in a non-backward-compatible - * manner between minor or incremental releases of NiFi. - * </p> - */ -public interface WriteResult { - - /** - * @return the number of records written - */ - int getRecordCount(); - - /** - * @return values that should be added to the FlowFile as attributes - */ - Map<String, String> getAttributes(); - - /** - * Creates a WriteResult with the given record count and attributes - * - * @param recordCount the number of records written - * @param attributes the attributes to add to the FlowFile - * @return A {@link WriteResult} representing the given parameters - */ - public static WriteResult of(final int recordCount, final Map<String, String> attributes) { - return new WriteResult() { - @Override - public int getRecordCount() { - return recordCount; - } - - @Override - public Map<String, String> getAttributes() { - return attributes; - } - }; - } - - public static final WriteResult EMPTY = of(0, Collections.emptyMap()); -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/DataType.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/DataType.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/DataType.java deleted file mode 100644 index 6ed4bd6..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/DataType.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization.record; - -import java.util.Objects; - -public class DataType { - private final RecordFieldType fieldType; - private final String format; - - protected DataType(final RecordFieldType fieldType, final String format) { - this.fieldType = fieldType; - this.format = format; - } - - public String getFormat() { - return format; - } - - public RecordFieldType getFieldType() { - return fieldType; - } - - @Override - public int hashCode() { - return 31 + 41 * getFieldType().hashCode() + 41 * (getFormat() == null ? 0 : getFormat().hashCode()); - } - - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof DataType)) { - return false; - } - - final DataType other = (DataType) obj; - return getFieldType().equals(other.getFieldType()) && Objects.equals(getFormat(), other.getFormat()); - } - - @Override - public String toString() { - if (getFormat() == null) { - return getFieldType().toString(); - } else { - return getFieldType().toString() + ":" + getFormat(); - } - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/ListRecordSet.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/ListRecordSet.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/ListRecordSet.java deleted file mode 100644 index 3968f50..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/ListRecordSet.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization.record; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class ListRecordSet implements RecordSet { - private final Iterator<Record> recordItr; - private final RecordSchema schema; - - public ListRecordSet(final RecordSchema schema, final List<Record> records) { - this.schema = schema; - - final List<Record> copy = new ArrayList<>(records); - recordItr = copy.iterator(); - } - - @Override - public RecordSchema getSchema() { - return schema; - } - - @Override - public Record next() { - return recordItr.hasNext() ? recordItr.next() : null; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/MapRecord.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/MapRecord.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/MapRecord.java deleted file mode 100644 index 56cf909..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/MapRecord.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization.record; - -import java.util.Date; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -import org.apache.nifi.serialization.record.util.DataTypeUtils; - -public class MapRecord implements Record { - private final RecordSchema schema; - private final Map<String, Object> values; - - public MapRecord(final RecordSchema schema, final Map<String, Object> values) { - this.schema = Objects.requireNonNull(schema); - this.values = Objects.requireNonNull(values); - } - - @Override - public RecordSchema getSchema() { - return schema; - } - - @Override - public Object[] getValues() { - final Object[] values = new Object[schema.getFieldCount()]; - int i = 0; - for (final RecordField recordField : schema.getFields()) { - values[i++] = getValue(recordField); - } - return values; - } - - @Override - public Object getValue(final String fieldName) { - final Optional<RecordField> fieldOption = schema.getField(fieldName); - if (fieldOption.isPresent()) { - return getValue(fieldOption.get()); - } - - return null; - } - - @Override - public Object getValue(final RecordField field) { - Object explicitValue = getExplicitValue(field); - if (explicitValue != null) { - return explicitValue; - } - - final Optional<RecordField> resolvedField = resolveField(field); - final boolean resolvedFieldDifferent = resolvedField.isPresent() && !resolvedField.get().equals(field); - if (resolvedFieldDifferent) { - explicitValue = getExplicitValue(resolvedField.get()); - if (explicitValue != null) { - return explicitValue; - } - } - - Object defaultValue = field.getDefaultValue(); - if (defaultValue != null) { - return defaultValue; - } - - if (resolvedFieldDifferent) { - return resolvedField.get().getDefaultValue(); - } - - return null; - } - - private Optional<RecordField> resolveField(final RecordField field) { - Optional<RecordField> resolved = schema.getField(field.getFieldName()); - if (resolved.isPresent()) { - return resolved; - } - - for (final String alias : field.getAliases()) { - resolved = schema.getField(alias); - if (resolved.isPresent()) { - return resolved; - } - } - - return Optional.empty(); - } - - private Object getExplicitValue(final RecordField field) { - final String canonicalFieldName = field.getFieldName(); - - // We use containsKey here instead of just calling get() and checking for a null value - // because if the true field name is set to null, we want to return null, rather than - // what the alias points to. Likewise for a specific alias, since aliases are defined - // in a List with a specific ordering. - Object value = values.get(canonicalFieldName); - if (value != null) { - return value; - } - - for (final String alias : field.getAliases()) { - value = values.get(alias); - if (value != null) { - return value; - } - } - - return null; - } - - @Override - public String getAsString(final String fieldName) { - final Optional<DataType> dataTypeOption = schema.getDataType(fieldName); - if (!dataTypeOption.isPresent()) { - return null; - } - - return convertToString(getValue(fieldName), dataTypeOption.get().getFormat()); - } - - @Override - public String getAsString(final String fieldName, final String format) { - return convertToString(getValue(fieldName), format); - } - - @Override - public String getAsString(final RecordField field, final String format) { - return convertToString(getValue(field), format); - } - - private String getFormat(final String optionalFormat, final RecordFieldType fieldType) { - return (optionalFormat == null) ? fieldType.getDefaultFormat() : optionalFormat; - } - - private String convertToString(final Object value, final String format) { - if (value == null) { - return null; - } - - final String dateFormat = getFormat(format, RecordFieldType.DATE); - final String timestampFormat = getFormat(format, RecordFieldType.TIMESTAMP); - final String timeFormat = getFormat(format, RecordFieldType.TIME); - return DataTypeUtils.toString(value, dateFormat, timeFormat, timestampFormat); - } - - @Override - public Long getAsLong(final String fieldName) { - return DataTypeUtils.toLong(getValue(fieldName), fieldName); - } - - @Override - public Integer getAsInt(final String fieldName) { - return DataTypeUtils.toInteger(getValue(fieldName), fieldName); - } - - @Override - public Double getAsDouble(final String fieldName) { - return DataTypeUtils.toDouble(getValue(fieldName), fieldName); - } - - @Override - public Float getAsFloat(final String fieldName) { - return DataTypeUtils.toFloat(getValue(fieldName), fieldName); - } - - @Override - public Record getAsRecord(String fieldName, final RecordSchema schema) { - return DataTypeUtils.toRecord(getValue(fieldName), schema, fieldName); - } - - @Override - public Boolean getAsBoolean(final String fieldName) { - return DataTypeUtils.toBoolean(getValue(fieldName), fieldName); - } - - @Override - public Date getAsDate(final String fieldName, final String format) { - return DataTypeUtils.toDate(getValue(fieldName), format, fieldName); - } - - @Override - public Object[] getAsArray(final String fieldName) { - return DataTypeUtils.toArray(getValue(fieldName), fieldName); - } - - - @Override - public int hashCode() { - return 31 + 41 * values.hashCode() + 7 * schema.hashCode(); - } - - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof MapRecord)) { - return false; - } - final MapRecord other = (MapRecord) obj; - return schema.equals(other.schema) && values.equals(other.values); - } - - @Override - public String toString() { - return "MapRecord[values=" + values + "]"; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/PushBackRecordSet.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/PushBackRecordSet.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/PushBackRecordSet.java deleted file mode 100644 index a186611..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/PushBackRecordSet.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization.record; - -import java.io.IOException; - -public class PushBackRecordSet implements RecordSet { - private final RecordSet original; - private Record pushback; - - public PushBackRecordSet(final RecordSet original) { - this.original = original; - } - - @Override - public RecordSchema getSchema() throws IOException { - return original.getSchema(); - } - - @Override - public Record next() throws IOException { - if (pushback != null) { - final Record record = pushback; - pushback = null; - return record; - } - - return original.next(); - } - - public void pushback(final Record record) { - if (pushback != null) { - throw new IllegalStateException("RecordSet already has a Record pushed back. Cannot push back more than one record at a time."); - } - - this.pushback = record; - } - - public boolean isAnotherRecord() throws IOException { - if (pushback != null) { - return true; - } - - final Record nextRecord = next(); - if (nextRecord == null) { - return false; - } - - pushback(nextRecord); - return true; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/Record.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/Record.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/Record.java deleted file mode 100644 index 5e5e7ba..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/Record.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization.record; - -import java.util.Date; - -public interface Record { - - RecordSchema getSchema(); - - /** - * <p> - * Returns a view of the the values of the fields in this Record. - * </p> - * - * <b>NOTE:</b> The array that is returned may be an underlying array that is backing - * the contents of the Record. As such, modifying the array in any way may result in - * modifying the record. - * - * @return a view of the values of the fields in this Record - */ - Object[] getValues(); - - Object getValue(String fieldName); - - Object getValue(RecordField field); - - String getAsString(String fieldName); - - String getAsString(String fieldName, String format); - - String getAsString(RecordField field, String format); - - Long getAsLong(String fieldName); - - Integer getAsInt(String fieldName); - - Double getAsDouble(String fieldName); - - Float getAsFloat(String fieldName); - - Record getAsRecord(String fieldName, RecordSchema schema); - - Boolean getAsBoolean(String fieldName); - - Date getAsDate(String fieldName, String format); - - Object[] getAsArray(String fieldName); -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordField.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordField.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordField.java deleted file mode 100644 index fe3d8e5..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordField.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization.record; - -import java.util.Collections; -import java.util.Objects; -import java.util.Set; - -import org.apache.nifi.serialization.record.util.DataTypeUtils; - -public class RecordField { - private final String fieldName; - private final DataType dataType; - private final Set<String> aliases; - private final Object defaultValue; - - public RecordField(final String fieldName, final DataType dataType) { - this(fieldName, dataType, null, Collections.emptySet()); - } - - public RecordField(final String fieldName, final DataType dataType, final Object defaultValue) { - this(fieldName, dataType, defaultValue, Collections.emptySet()); - } - - public RecordField(final String fieldName, final DataType dataType, final Set<String> aliases) { - this(fieldName, dataType, null, aliases); - } - - public RecordField(final String fieldName, final DataType dataType, final Object defaultValue, final Set<String> aliases) { - if (defaultValue != null && !DataTypeUtils.isCompatibleDataType(defaultValue, dataType)) { - throw new IllegalArgumentException("Cannot set the default value for field [" + fieldName + "] to [" + defaultValue - + "] because that is not a valid value for Data Type [" + dataType + "]"); - } - - this.fieldName = Objects.requireNonNull(fieldName); - this.dataType = Objects.requireNonNull(dataType); - this.aliases = Collections.unmodifiableSet(Objects.requireNonNull(aliases)); - this.defaultValue = defaultValue; - } - - public String getFieldName() { - return fieldName; - } - - public Set<String> getAliases() { - return aliases; - } - - public DataType getDataType() { - return dataType; - } - - public Object getDefaultValue() { - return defaultValue; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + dataType.hashCode(); - result = prime * result + fieldName.hashCode(); - result = prime * result + aliases.hashCode(); - result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - - if (getClass() != obj.getClass()) { - return false; - } - - RecordField other = (RecordField) obj; - return dataType.equals(other.getDataType()) && fieldName.equals(other.getFieldName()) && aliases.equals(other.getAliases()) && Objects.equals(defaultValue, other.defaultValue); - } - - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordFieldType.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordFieldType.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordFieldType.java deleted file mode 100644 index 785b8d2..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordFieldType.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization.record; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.nifi.serialization.record.type.ArrayDataType; -import org.apache.nifi.serialization.record.type.ChoiceDataType; -import org.apache.nifi.serialization.record.type.MapDataType; -import org.apache.nifi.serialization.record.type.RecordDataType; - -public enum RecordFieldType { - /** - * A String field type. Fields of this type use a {@code java.lang.String} value. - */ - STRING("string"), - - /** - * A boolean field type. Fields of this type use a {@code boolean} value. - */ - BOOLEAN("boolean"), - - /** - * A byte field type. Fields of this type use a {@code byte} value. - */ - BYTE("byte"), - - /** - * A char field type. Fields of this type use a {@code char} value. - */ - CHAR("char"), - - /** - * A short field type. Fields of this type use a {@code short} value. - */ - SHORT("short"), - - /** - * An int field type. Fields of this type use an {@code int} value. - */ - INT("int"), - - /** - * A bigint field type. Fields of this type use a {@code java.math.BigInteger} value. - */ - BIGINT("bigint"), - - /** - * A long field type. Fields of this type use a {@code long} value. - */ - LONG("long"), - - /** - * A float field type. Fields of this type use a {@code float} value. - */ - FLOAT("float"), - - /** - * A double field type. Fields of this type use a {@code double} value. - */ - DOUBLE("double"), - - /** - * A date field type. Fields of this type use a {@code java.sql.Date} value. - */ - DATE("date", "yyyy-MM-dd"), - - /** - * A time field type. Fields of this type use a {@code java.sql.Time} value. - */ - TIME("time", "HH:mm:ss"), - - /** - * A timestamp field type. Fields of this type use a {@code java.sql.Timestamp} value. - */ - TIMESTAMP("timestamp", "yyyy-MM-dd HH:mm:ss"), - - /** - * <p> - * A record field type. Fields of this type use a {@code org.apache.nifi.serialization.record.Record} value. A Record DataType should be - * created by providing the {@link RecordSchema} for the record: - * </p> - * - * <code> - * final DataType recordType = RecordFieldType.RECORD.getRecordDataType(recordSchema); - * </code> - * - * <p> - * A field of type RECORD should always have a {@link RecordDataType}, so the following idiom is acceptable for use: - * </p> - * - * <code> - * <pre> - * final DataType dataType = ...; - * if (dataType.getFieldType() == RecordFieldType.RECORD) { - * final RecordDataType recordDataType = (RecordDataType) dataType; - * final RecordSchema childSchema = recordDataType.getChildSchema(); - * ... - * } - * </pre> - * </code> - */ - RECORD("record", null, new RecordDataType(null)), - - /** - * <p> - * A choice field type. A field of type choice can be one of any number of different types, which are defined by the DataType that is used. - * For example, if a field should allow either a Long or an Integer, this can be accomplished by using: - * </p> - * - * <code> - * final DataType choiceType = RecordFieldType.CHOICE.getChoiceDataType( RecordFieldType.INT.getDataType(), RecordFieldType.LONG.getDataType() ); - * </code> - * - * <p> - * A field of type CHOICE should always have a {@link ChoiceDataType}, so the following idiom is acceptable for use: - * </p> - * - * <code> - * <pre> - * final DataType dataType = ...; - * if (dataType.getFieldType() == RecordFieldType.CHOICE) { - * final ChoiceDataType choiceDataType = (ChoiceDataType) dataType; - * final List<DataType> allowableTypes = choiceDataType.getPossibleSubTypes(); - * ... - * } - * </pre> - * </code> - */ - CHOICE("choice", null, new ChoiceDataType(Collections.emptyList())), - - /** - * <p> - * An array field type. Fields of this type use a {@code Object[]} value. Note that we are explicitly indicating that - * Object[] should be used here and not primitive array types. For instance, setting a value of {@code int[]} is not allowed. The DataType for - * this field should be created using the {@link #getArrayDataType(DataType)} method: - * </p> - * - * <code> - * final DataType arrayType = RecordFieldType.ARRAY.getArrayDataType( RecordFieldType.INT.getDataType() ); - * </code> - * - * <p> - * A field of type ARRAY should always have an {@link ArrayDataType}, so the following idiom is acceptable for use: - * </p> - * - * <code> - * <pre> - * final DataType dataType = ...; - * if (dataType.getFieldType() == RecordFieldType.ARRAY) { - * final ArrayDataType arrayDataType = (ArrayDataType) dataType; - * final DataType elementType = arrayDataType.getElementType(); - * ... - * } - * </pre> - * </code> - */ - ARRAY("array", null, new ArrayDataType(null)), - - /** - * <p> - * A record field type. Fields of this type use a {@code Map<String, Object>} value. A Map DataType should be - * created by providing the {@link DataType} for the values: - * </p> - * - * <code> - * final DataType recordType = RecordFieldType.MAP.getRecordDataType( RecordFieldType.STRING.getDataType() ); - * </code> - * - * <p> - * A field of type MAP should always have a {@link MapDataType}, so the following idiom is acceptable for use: - * </p> - * - * <code> - * <pre> - * final DataType dataType = ...; - * if (dataType.getFieldType() == RecordFieldType.MAP) { - * final MapDataType mapDataType = (MapDataType) dataType; - * final DataType valueType = mapDataType.getValueType(); - * ... - * } - * </pre> - * </code> - */ - MAP("map", null, new MapDataType(null)); - - - private static final Map<String, RecordFieldType> SIMPLE_NAME_MAP = new HashMap<String, RecordFieldType>(); - - static { - for (RecordFieldType value : values()) { - SIMPLE_NAME_MAP.put(value.simpleName, value); - } - } - - private final String simpleName; - private final String defaultFormat; - private final DataType defaultDataType; - - private RecordFieldType(final String simpleName) { - this(simpleName, null); - } - - private RecordFieldType(final String simpleName, final String defaultFormat) { - this.simpleName = simpleName; - this.defaultFormat = defaultFormat; - this.defaultDataType = new DataType(this, defaultFormat); - } - - private RecordFieldType(final String simpleName, final String defaultFormat, final DataType defaultDataType) { - this.simpleName = simpleName; - this.defaultFormat = defaultFormat; - this.defaultDataType = defaultDataType; - } - - public String getDefaultFormat() { - return defaultFormat; - } - - /** - * @return the DataType with the default format - */ - public DataType getDataType() { - return defaultDataType; - } - - public DataType getDataType(final String format) { - return new DataType(this, format); - } - - /** - * Returns a Data Type that represents a "RECORD" or "ARRAY" type with the given schema. - * - * @param childSchema the Schema for the Record or Array - * @return a DataType that represents a Record or Array with the given schema, or <code>null</code> if this RecordFieldType - * is not the RECORD or ARRAY type. - */ - public DataType getRecordDataType(final RecordSchema childSchema) { - if (this != RECORD) { - return null; - } - - return new RecordDataType(childSchema); - } - - /** - * Returns a Data Type that represents an "ARRAY" type with the given element type. - * - * @param elementType the type of the arrays in the element - * @return a DataType that represents an Array with the given element type, or <code>null</code> if this RecordFieldType - * is not the ARRAY type. - */ - public DataType getArrayDataType(final DataType elementType) { - if (this != ARRAY) { - return null; - } - - return new ArrayDataType(elementType); - } - - - /** - * Returns a Data Type that represents a "CHOICE" of multiple possible types. This method is - * only applicable for a RecordFieldType of {@link #CHOICE}. - * - * @param possibleChildTypes the possible types that are allowable - * @return a DataType that represents a "CHOICE" of multiple possible types, or <code>null</code> if this RecordFieldType - * is not the CHOICE type. - */ - public DataType getChoiceDataType(final List<DataType> possibleChildTypes) { - if (this != CHOICE) { - return null; - } - - return new ChoiceDataType(possibleChildTypes); - } - - /** - * Returns a Data Type that represents a "CHOICE" of multiple possible types. This method is - * only applicable for a RecordFieldType of {@link #CHOICE}. - * - * @param possibleChildTypes the possible types that are allowable - * @return a DataType that represents a "CHOICE" of multiple possible types, or <code>null</code> if this RecordFieldType - * is not the CHOICE type. - */ - public DataType getChoiceDataType(final DataType... possibleChildTypes) { - if (this != CHOICE) { - return null; - } - - final List<DataType> list = new ArrayList<>(possibleChildTypes.length); - for (final DataType type : possibleChildTypes) { - list.add(type); - } - - return new ChoiceDataType(list); - } - - /** - * Returns a Data Type that represents a "MAP" type with the given value type. - * - * @param valueDataType the type of the values in the map - * @return a DataType that represents a Map with the given value type, or <code>null</code> if this RecordFieldType - * is not the MAP type. - */ - public DataType getMapDataType(final DataType valueDataType) { - if (this != MAP) { - return null; - } - - return new MapDataType(valueDataType); - } - - - public static RecordFieldType of(final String typeString) { - return SIMPLE_NAME_MAP.get(typeString); - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordSchema.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordSchema.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordSchema.java deleted file mode 100644 index 367f2b0..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordSchema.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization.record; - -import java.util.List; -import java.util.Optional; - -public interface RecordSchema { - /** - * @return the list of fields that are present in the schema - */ - List<RecordField> getFields(); - - /** - * @return the number of fields in the schema - */ - int getFieldCount(); - - /** - * @param index the 0-based index of which field to return - * @return the index'th field - * - * @throws IndexOutOfBoundsException if the index is < 0 or >= the number of fields (determined by {@link #getFieldCount()}). - */ - RecordField getField(int index); - - /** - * @return the data types of the fields - */ - List<DataType> getDataTypes(); - - /** - * @return the names of the fields - */ - List<String> getFieldNames(); - - /** - * @param fieldName the name of the field whose type is desired - * @return the RecordFieldType associated with the field that has the given name, or - * <code>null</code> if the schema does not contain a field with the given name - */ - Optional<DataType> getDataType(String fieldName); - - /** - * @return the textual representation of the schema, if one is available - */ - Optional<String> getSchemaText(); - - /** - * @return the format of the schema text, if schema text is present - */ - Optional<String> getSchemaFormat(); - - /** - * @param fieldName the name of the field - * @return an Optional RecordField for the field with the given name - */ - Optional<RecordField> getField(String fieldName); - - /** - * @return the SchemaIdentifier, which provides various attributes for identifying a schema - */ - SchemaIdentifier getIdentifier(); -} http://git-wip-us.apache.org/repos/asf/nifi/blob/60d88b5a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordSet.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordSet.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordSet.java deleted file mode 100644 index 9e67346..0000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-service-api/src/main/java/org/apache/nifi/serialization/record/RecordSet.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.serialization.record; - -import java.io.IOException; - -public interface RecordSet { - - /** - * @return the {@link RecordSchema} that applies to the records in this RecordSet - */ - RecordSchema getSchema() throws IOException; - - /** - * @return the next {@link Record} in the set or <code>null</code> if there are no more records - */ - Record next() throws IOException; - - /** - * Returns a new Record Set that will return no more than {@code maxRecords} records from this - * RecordSet. Any Records that are pulled from this newly created RecordSet will also advance - * the cursor in this Record Set and vice versa. - * - * @param maxRecords the maximum number of records to return from the new RecordSet - * @return a view of this RecordSet that limits the number of records returned - */ - default RecordSet limit(final int maxRecords) { - if (maxRecords < 0) { - throw new IllegalArgumentException("Cannot limit number of records to " + maxRecords + ". Limit must be a non-negative integer"); - } - - final RecordSet original = this; - return new RecordSet() { - private int count = 0; - - @Override - public RecordSchema getSchema() throws IOException { - return original.getSchema(); - } - - @Override - public Record next() throws IOException { - if (count >= maxRecords) { - return null; - } - - final Record record = original.next(); - if (record != null) { - count++; - } - - return record; - } - }; - } - - public static RecordSet of(final RecordSchema schema, final Record... records) { - return new RecordSet() { - private int index = 0; - - @Override - public RecordSchema getSchema() { - return schema; - } - - @Override - public Record next() { - if (index >= records.length) { - return null; - } - - return records[index++]; - } - }; - } -}
