mattyb149 commented on a change in pull request #3253: NIFI-5938: Added ability 
to infer record schema on read from JsonTree…
URL: https://github.com/apache/nifi/pull/3253#discussion_r251517480
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/schema/inference/SchemaInferenceUtil.java
 ##########
 @@ -0,0 +1,59 @@
+/*
+ * 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.inference;
+
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.PropertyDescriptor.Builder;
+import org.apache.nifi.context.PropertyContext;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.schema.access.SchemaAccessStrategy;
+import org.apache.nifi.serialization.RecordSchemaCacheService;
+
+import java.util.function.Supplier;
+
+public class SchemaInferenceUtil {
+    public static final AllowableValue INFER_SCHEMA = new 
AllowableValue("infer-schema", "Infer Schema",
 
 Review comment:
   Should we add either another option (or hardcode the behavior) to normalize 
the field names when creating a Avro schema? Alternatively we'd need a way for 
each reader (possibly writer as well?) to skip field validation when doing 
schema things. We have such a thing in the AvroSchemaRegistry, but I think it'd 
be required for schema inference to be fully useful.
   
   I ran into this when inferring the schema for provenance events, some 
attributes have `.` in the name, which causes a failure when extracting the 
schema:
   
   ```
   2019-01-28 12:32:03,735 ERROR [Timer-Driven Process Thread-8] 
o.a.nifi.processors.standard.MergeRecord 
MergeRecord[id=3ae34ae7-0166-1000-c69a-5846d15a6584] Failed to bin 
StandardFlowFileRecord[uuid=caa4fecc-b9fc-4e6b-ad8b-a2816a2197f3,claim=StandardContentClaim
 [resourceClaim=StandardResourceClaim[id=1548696079376-335, container=default, 
section=335], offset=131218, 
length=1387],offset=0,name=caa4fecc-b9fc-4e6b-ad8b-a2816a2197f3,size=1387] due 
to org.apache.avro.SchemaParseException: Illegal character in: 
reporting.task.type: org.apache.avro.SchemaParseException: Illegal character 
in: reporting.task.type
   org.apache.avro.SchemaParseException: Illegal character in: 
reporting.task.type
        at org.apache.avro.Schema.validateName(Schema.java:1151)
        at org.apache.avro.Schema.access$200(Schema.java:81)
        at org.apache.avro.Schema$Field.<init>(Schema.java:403)
        at org.apache.avro.Schema$Field.<init>(Schema.java:423)
        at org.apache.avro.Schema$Field.<init>(Schema.java:415)
        at 
org.apache.nifi.avro.AvroTypeUtil.buildAvroField(AvroTypeUtil.java:122)
        at 
org.apache.nifi.avro.AvroTypeUtil.buildAvroSchema(AvroTypeUtil.java:203)
        at 
org.apache.nifi.avro.AvroTypeUtil.buildAvroField(AvroTypeUtil.java:121)
        at 
org.apache.nifi.avro.AvroTypeUtil.buildAvroSchema(AvroTypeUtil.java:113)
        at 
org.apache.nifi.avro.AvroTypeUtil.extractAvroSchema(AvroTypeUtil.java:93)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to