[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user asfgit closed the pull request at: https://github.com/apache/nifi/pull/2619 ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r199602436 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/TestSchemaRegistry.java --- @@ -0,0 +1,49 @@ +/* + * 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.mongodb; + +import org.apache.nifi.controller.AbstractControllerService; +import org.apache.nifi.schema.access.SchemaField; +import org.apache.nifi.schemaregistry.services.SchemaRegistry; +import org.apache.nifi.serialization.SimpleRecordSchema; +import org.apache.nifi.serialization.record.RecordField; +import org.apache.nifi.serialization.record.RecordFieldType; +import org.apache.nifi.serialization.record.RecordSchema; +import org.apache.nifi.serialization.record.SchemaIdentifier; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestSchemaRegistry extends AbstractControllerService implements SchemaRegistry { --- End diff -- Yeah. Changed it to StubSchemaRegistry. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r199600826 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/serialization/JsonInferenceSchemaRegistryService.java --- @@ -0,0 +1,103 @@ +/* + * 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 org.apache.nifi.annotation.lifecycle.OnEnabled; +import org.apache.nifi.components.AllowableValue; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.PropertyValue; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.schema.access.AvroSchemaTextStrategy; +import org.apache.nifi.schema.access.InferenceSchemaStrategy; +import org.apache.nifi.schema.access.JsonSchemaAccessStrategy; +import org.apache.nifi.schema.access.SchemaAccessStrategy; +import org.apache.nifi.schema.access.SchemaNamePropertyStrategy; +import org.apache.nifi.schema.access.SchemaNotFoundException; +import org.apache.nifi.schemaregistry.services.SchemaRegistry; +import org.apache.nifi.serialization.record.RecordSchema; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static org.apache.nifi.schema.access.SchemaAccessUtils.INFER_SCHEMA; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_BRANCH_NAME; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_NAME; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_NAME_PROPERTY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_REGISTRY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_TEXT; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_TEXT_PROPERTY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_VERSION; + +public class JsonInferenceSchemaRegistryService extends SchemaRegistryService { +private String schemaAccess; + +@OnEnabled +public void onEnabled(ConfigurationContext context) { +this.storeSchemaAccessStrategy(context); +this.schemaAccess = context.getProperty(getSchemaAcessStrategyDescriptor()).getValue(); +} + +@Override +protected SchemaAccessStrategy getSchemaAccessStrategy(final String strategy, final SchemaRegistry schemaRegistry, final ConfigurationContext context) { --- End diff -- Done. I think that probably is the right thing to do here. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r199597348 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/schema/access/SchemaAccessUtils.java --- @@ -50,7 +50,7 @@ "The content of the FlowFile contains a reference to a schema in the Schema Registry service. The reference is encoded as a single " + "'Magic Byte' followed by 4 bytes representing the identifier of the schema, as outlined at http://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html. " + "This is based on version 3.2.x of the Confluent Schema Registry."); - +public static final AllowableValue INFER_SCHEMA = new AllowableValue("infer", "Infer from JSON"); --- End diff -- Probably. I'll go ahead and make that change. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r199518028 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/serialization/JsonInferenceSchemaRegistryService.java --- @@ -0,0 +1,103 @@ +/* + * 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 org.apache.nifi.annotation.lifecycle.OnEnabled; +import org.apache.nifi.components.AllowableValue; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.PropertyValue; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.schema.access.AvroSchemaTextStrategy; +import org.apache.nifi.schema.access.InferenceSchemaStrategy; +import org.apache.nifi.schema.access.JsonSchemaAccessStrategy; +import org.apache.nifi.schema.access.SchemaAccessStrategy; +import org.apache.nifi.schema.access.SchemaNamePropertyStrategy; +import org.apache.nifi.schema.access.SchemaNotFoundException; +import org.apache.nifi.schemaregistry.services.SchemaRegistry; +import org.apache.nifi.serialization.record.RecordSchema; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static org.apache.nifi.schema.access.SchemaAccessUtils.INFER_SCHEMA; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_BRANCH_NAME; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_NAME; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_NAME_PROPERTY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_REGISTRY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_TEXT; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_TEXT_PROPERTY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_VERSION; + +public class JsonInferenceSchemaRegistryService extends SchemaRegistryService { +private String schemaAccess; + +@OnEnabled +public void onEnabled(ConfigurationContext context) { +this.storeSchemaAccessStrategy(context); +this.schemaAccess = context.getProperty(getSchemaAcessStrategyDescriptor()).getValue(); +} + +@Override +protected SchemaAccessStrategy getSchemaAccessStrategy(final String strategy, final SchemaRegistry schemaRegistry, final ConfigurationContext context) { --- End diff -- Since this impl is specifically for JSON inference, perhaps it should override getDefaultSchemaAccessStrategy() to return the Infer one? ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r199519266 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/TestSchemaRegistry.java --- @@ -0,0 +1,49 @@ +/* + * 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.mongodb; + +import org.apache.nifi.controller.AbstractControllerService; +import org.apache.nifi.schema.access.SchemaField; +import org.apache.nifi.schemaregistry.services.SchemaRegistry; +import org.apache.nifi.serialization.SimpleRecordSchema; +import org.apache.nifi.serialization.record.RecordField; +import org.apache.nifi.serialization.record.RecordFieldType; +import org.apache.nifi.serialization.record.RecordSchema; +import org.apache.nifi.serialization.record.SchemaIdentifier; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestSchemaRegistry extends AbstractControllerService implements SchemaRegistry { --- End diff -- Should this be called StubSchemaRegistry or MockSchemaRegistry? With Test at the front, I imagine it gets picked up by JUnit (although there are no @Test methods, but still) ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r199517358 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/schema/access/SchemaAccessUtils.java --- @@ -50,7 +50,7 @@ "The content of the FlowFile contains a reference to a schema in the Schema Registry service. The reference is encoded as a single " + "'Magic Byte' followed by 4 bytes representing the identifier of the schema, as outlined at http://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html. " + "This is based on version 3.2.x of the Confluent Schema Registry."); - +public static final AllowableValue INFER_SCHEMA = new AllowableValue("infer", "Infer from JSON"); --- End diff -- Shouldn't this be "Infer from Result" or something? It could be used by other processors to infer the schema from whatever object is returned. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193770298 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-standard-record-utils/src/main/java/org/apache/nifi/schema/access/JsonSchemaAccessStrategy.java --- @@ -0,0 +1,36 @@ +/* + * 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; + +import org.apache.nifi.serialization.record.RecordSchema; + +import java.io.IOException; +import java.util.Map; + +public interface JsonSchemaAccessStrategy extends SchemaAccessStrategy { --- End diff -- You're not missing anything... ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193740195 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/serialization/JsonInferenceSchemaRegistryService.java --- @@ -0,0 +1,77 @@ +/* + * 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 org.apache.nifi.annotation.lifecycle.OnEnabled; +import org.apache.nifi.components.AllowableValue; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.schema.access.JsonSchemaAccessStrategy; +import org.apache.nifi.schema.access.SchemaNotFoundException; +import org.apache.nifi.serialization.record.RecordSchema; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static org.apache.nifi.schema.access.SchemaAccessUtils.INFER_SCHEMA; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_BRANCH_NAME; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_NAME; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_NAME_PROPERTY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_REGISTRY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_TEXT; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_TEXT_PROPERTY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_VERSION; + +public class JsonInferenceSchemaRegistryService extends SchemaRegistryService { --- End diff -- Yeah, if this gets expanded into the readers I could definitely see that being the case. For now, this is limited to being used by LookupServices that need schema access + JSON help like this one, the ES one and possibly later something like a RethinkDBLookupService. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user bbende commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193739859 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-standard-record-utils/src/main/java/org/apache/nifi/schema/access/JsonSchemaAccessStrategy.java --- @@ -0,0 +1,36 @@ +/* + * 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; + +import org.apache.nifi.serialization.record.RecordSchema; + +import java.io.IOException; +import java.util.Map; + +public interface JsonSchemaAccessStrategy extends SchemaAccessStrategy { --- End diff -- Ok but I'm confused because I'm not seeing an actual call that uses the new method... The MongoLookupService does this: ``` private RecordSchema loadSchema(Map coordinates, Document doc) { +Map variables = coordinates.entrySet().stream() +.collect(Collectors.toMap( +e -> e.getKey(), +e -> e.getValue().toString() +)); +ObjectMapper mapper = new ObjectMapper(); +try { +byte[] bytes = mapper.writeValueAsBytes(doc); +return getSchema(variables, new ByteArrayInputStream(bytes), null); +} catch (Exception ex) { +return null; +} +} So since we are reserializing the Doc here and putting the coordinates as variables, I'm not seeing where we call the new method, but I may be missing it. ``` ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193738667 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/schema/access/SchemaAccessUtils.java --- @@ -176,6 +176,8 @@ public static SchemaAccessStrategy getSchemaAccessStrategy(final String allowabl return new HortonworksAttributeSchemaReferenceStrategy(schemaRegistry); } else if (allowableValue.equalsIgnoreCase(CONFLUENT_ENCODED_SCHEMA.getValue())) { return new ConfluentSchemaRegistryStrategy(schemaRegistry); +} else if (allowableValue.equalsIgnoreCase(INFER_SCHEMA.getValue())) { --- End diff -- Ok. I'll work on that. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193737082 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-standard-record-utils/src/main/java/org/apache/nifi/schema/access/JsonSchemaAccessStrategy.java --- @@ -0,0 +1,36 @@ +/* + * 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; + +import org.apache.nifi.serialization.record.RecordSchema; + +import java.io.IOException; +import java.util.Map; + +public interface JsonSchemaAccessStrategy extends SchemaAccessStrategy { --- End diff -- The client APIs for the third party systems usually return a Map, not a String that we can just pass on. I didn't want to serialize the client's output and then deserialize it later. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user bbende commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193734191 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-standard-record-utils/src/main/java/org/apache/nifi/schema/access/JsonSchemaAccessStrategy.java --- @@ -0,0 +1,36 @@ +/* + * 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; + +import org.apache.nifi.serialization.record.RecordSchema; + +import java.io.IOException; +import java.util.Map; + +public interface JsonSchemaAccessStrategy extends SchemaAccessStrategy { --- End diff -- Can this be done without introducing a new method to the interface? The original interface has: `getSchema(Map variables, InputStream contentStream, RecordSchema readSchema` Since we know the content has to be json in this case, can't we read contentStream into the Map in the implementation of the access strategy, rather than requiring callers to do that first? ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user bbende commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193735509 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/serialization/JsonInferenceSchemaRegistryService.java --- @@ -0,0 +1,77 @@ +/* + * 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 org.apache.nifi.annotation.lifecycle.OnEnabled; +import org.apache.nifi.components.AllowableValue; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.schema.access.JsonSchemaAccessStrategy; +import org.apache.nifi.schema.access.SchemaNotFoundException; +import org.apache.nifi.serialization.record.RecordSchema; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static org.apache.nifi.schema.access.SchemaAccessUtils.INFER_SCHEMA; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_BRANCH_NAME; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_NAME; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_NAME_PROPERTY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_REGISTRY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_TEXT; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_TEXT_PROPERTY; +import static org.apache.nifi.schema.access.SchemaAccessUtils.SCHEMA_VERSION; + +public class JsonInferenceSchemaRegistryService extends SchemaRegistryService { --- End diff -- I'm not totally sure about this, but I think if we take the approach mentioned in my other comments, we probably wouldn't need this class since the JSON readers would handle the logic for when schemaAccess is set to "JSON Inference", similar to how AvroReader handles when embedded schema is selected - https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/avro/AvroReader.java#L78 ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user bbende commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193733115 --- Diff: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/schema/access/SchemaAccessUtils.java --- @@ -176,6 +176,8 @@ public static SchemaAccessStrategy getSchemaAccessStrategy(final String allowabl return new HortonworksAttributeSchemaReferenceStrategy(schemaRegistry); } else if (allowableValue.equalsIgnoreCase(CONFLUENT_ENCODED_SCHEMA.getValue())) { return new ConfluentSchemaRegistryStrategy(schemaRegistry); +} else if (allowableValue.equalsIgnoreCase(INFER_SCHEMA.getValue())) { --- End diff -- Since this inference only works when the content is JSON, I think this option should only be available when using a JSON related record reader, and not available in the default case. This would be similar to how the AvroReader makes available the option for "Embedded Avro Schema" - https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/avro/AvroReader.java#L63 ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193480390 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() +.name("mongo-lookup-client-service") +.displayName("Client Service") +.description("A MongoDB controller service to use with this lookup service.") +.required(true) +.identifiesControllerService(MongoDBClientService.class) +.build(); public static final PropertyDescriptor LOOKUP_VALUE_FIELD = new PropertyDescriptor.Builder() -.name("mongo-lookup-value-field") -.displayName("Lookup Value Field") -.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + -"MongoDB result document minus the _id field will be returned as a record.") -.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) -.required(false) -.build(); +.name("mongo-lookup-value-field") +.displayName("Lookup Value Field") +.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + +"MongoDB result document minus the _id field will be returned as a record.") +.addValidator(Validator.VALID) +.required(false) +.build(); +public static final PropertyDescriptor PROJECTION = new PropertyDescriptor.Builder() +.name("mongo-lookup-projection") +.displayName("Projection") +.description("Specifies a projection for limiting which fields will be returned.") +.required(false) +.build(); private String lookupValueField; -private static final List lookupDescriptors; - -static { -lookupDescriptors = new ArrayList<>(); -lookupDescriptors.addAll(descriptors); -lookupDescriptors.add(LOOKUP_VALUE_FIELD); -} - @Override public Optional lookup(Map coordinates) throws LookupFailureException { -Map clean = new HashMap<>(); -clean.putAll(coordinates); +Map clean = coordinates.entrySet().stream() +.filter(e -> !schemaNameProperty.equals(String.format("${%s}", e.getKey( +.collect(Collectors.toMap( +e -> e.getKey(), +e -> e.getValue() +)); Document query = new Document(clean); if (coordinates.size() == 0) { throw new LookupFailureException("No keys were configured. Mongo query would return random documents."); } try { -Document result = this.findOne(query); +Document result = projection != null ? controllerService.findOne(query, projection) : controllerService.findOne(query); if(result == null) { return Optional.empty(); } else if (!StringUtils.isEmpty(lookupValueField)) { return Optional.ofNullable(result.get(lookupValueField)); } else { -final List fields = new ArrayList<>(); +RecordSchema schema = loadSchema(coordinates); -for (String key : result.keySet()) { -if (key.equals("_id")) { -continue; -} -fields.add(new RecordField(key, RecordFieldType.STRING.getDataType())); -} - -final RecordSchema schema = new SimpleRecordSchema(fields); -return Optional.ofNullable(new MapRecord(schema, result)); +RecordSchema toUse = schema != null ? schema : convertSchema(result); --- End diff -- That's probably the right way to do it because we should have it blow up if it can't get the schema on the first pass instead of silently falling back onto the inference option. Once I get that worked out, I'll copy pasta it over the ES one as well. --
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193406221 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() +.name("mongo-lookup-client-service") +.displayName("Client Service") +.description("A MongoDB controller service to use with this lookup service.") +.required(true) +.identifiesControllerService(MongoDBClientService.class) +.build(); public static final PropertyDescriptor LOOKUP_VALUE_FIELD = new PropertyDescriptor.Builder() -.name("mongo-lookup-value-field") -.displayName("Lookup Value Field") -.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + -"MongoDB result document minus the _id field will be returned as a record.") -.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) -.required(false) -.build(); +.name("mongo-lookup-value-field") +.displayName("Lookup Value Field") +.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + +"MongoDB result document minus the _id field will be returned as a record.") +.addValidator(Validator.VALID) +.required(false) +.build(); +public static final PropertyDescriptor PROJECTION = new PropertyDescriptor.Builder() +.name("mongo-lookup-projection") +.displayName("Projection") +.description("Specifies a projection for limiting which fields will be returned.") +.required(false) +.build(); private String lookupValueField; -private static final List lookupDescriptors; - -static { -lookupDescriptors = new ArrayList<>(); -lookupDescriptors.addAll(descriptors); -lookupDescriptors.add(LOOKUP_VALUE_FIELD); -} - @Override public Optional lookup(Map coordinates) throws LookupFailureException { -Map clean = new HashMap<>(); -clean.putAll(coordinates); +Map clean = coordinates.entrySet().stream() +.filter(e -> !schemaNameProperty.equals(String.format("${%s}", e.getKey( +.collect(Collectors.toMap( +e -> e.getKey(), +e -> e.getValue() +)); Document query = new Document(clean); if (coordinates.size() == 0) { throw new LookupFailureException("No keys were configured. Mongo query would return random documents."); } try { -Document result = this.findOne(query); +Document result = projection != null ? controllerService.findOne(query, projection) : controllerService.findOne(query); if(result == null) { return Optional.empty(); } else if (!StringUtils.isEmpty(lookupValueField)) { return Optional.ofNullable(result.get(lookupValueField)); } else { -final List fields = new ArrayList<>(); +RecordSchema schema = loadSchema(coordinates); -for (String key : result.keySet()) { -if (key.equals("_id")) { -continue; -} -fields.add(new RecordField(key, RecordFieldType.STRING.getDataType())); -} - -final RecordSchema schema = new SimpleRecordSchema(fields); -return Optional.ofNullable(new MapRecord(schema, result)); +RecordSchema toUse = schema != null ? schema : convertSchema(result); --- End diff -- One thing you could do is to override getSupportedPropertyDescriptors() and add your own property for Schema Access Strategy that only has the relevant ones, including your own strategy of "Infer Schema From Document" or something. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r193381877 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() +.name("mongo-lookup-client-service") +.displayName("Client Service") +.description("A MongoDB controller service to use with this lookup service.") +.required(true) +.identifiesControllerService(MongoDBClientService.class) +.build(); public static final PropertyDescriptor LOOKUP_VALUE_FIELD = new PropertyDescriptor.Builder() -.name("mongo-lookup-value-field") -.displayName("Lookup Value Field") -.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + -"MongoDB result document minus the _id field will be returned as a record.") -.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) -.required(false) -.build(); +.name("mongo-lookup-value-field") +.displayName("Lookup Value Field") +.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + +"MongoDB result document minus the _id field will be returned as a record.") +.addValidator(Validator.VALID) +.required(false) +.build(); +public static final PropertyDescriptor PROJECTION = new PropertyDescriptor.Builder() +.name("mongo-lookup-projection") +.displayName("Projection") +.description("Specifies a projection for limiting which fields will be returned.") +.required(false) +.build(); private String lookupValueField; -private static final List lookupDescriptors; - -static { -lookupDescriptors = new ArrayList<>(); -lookupDescriptors.addAll(descriptors); -lookupDescriptors.add(LOOKUP_VALUE_FIELD); -} - @Override public Optional lookup(Map coordinates) throws LookupFailureException { -Map clean = new HashMap<>(); -clean.putAll(coordinates); +Map clean = coordinates.entrySet().stream() +.filter(e -> !schemaNameProperty.equals(String.format("${%s}", e.getKey( +.collect(Collectors.toMap( +e -> e.getKey(), +e -> e.getValue() +)); Document query = new Document(clean); if (coordinates.size() == 0) { throw new LookupFailureException("No keys were configured. Mongo query would return random documents."); } try { -Document result = this.findOne(query); +Document result = projection != null ? controllerService.findOne(query, projection) : controllerService.findOne(query); if(result == null) { return Optional.empty(); } else if (!StringUtils.isEmpty(lookupValueField)) { return Optional.ofNullable(result.get(lookupValueField)); } else { -final List fields = new ArrayList<>(); +RecordSchema schema = loadSchema(coordinates); -for (String key : result.keySet()) { -if (key.equals("_id")) { -continue; -} -fields.add(new RecordField(key, RecordFieldType.STRING.getDataType())); -} - -final RecordSchema schema = new SimpleRecordSchema(fields); -return Optional.ofNullable(new MapRecord(schema, result)); +RecordSchema toUse = schema != null ? schema : convertSchema(result); --- End diff -- @mattyb149 I think the answer to your last question is here. If you specify `schema.name` in the coordinates, it'll get that from `loadSchema`. If not, it calls `convertSchema`. The rest of the lookup strategies don't make much sense in this case so I ca
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r192841468 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() +.name("mongo-lookup-client-service") +.displayName("Client Service") +.description("A MongoDB controller service to use with this lookup service.") +.required(true) +.identifiesControllerService(MongoDBControllerService.class) +.build(); public static final PropertyDescriptor LOOKUP_VALUE_FIELD = new PropertyDescriptor.Builder() -.name("mongo-lookup-value-field") -.displayName("Lookup Value Field") -.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + -"MongoDB result document minus the _id field will be returned as a record.") -.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) -.required(false) -.build(); +.name("mongo-lookup-value-field") +.displayName("Lookup Value Field") +.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + +"MongoDB result document minus the _id field will be returned as a record.") +.addValidator(Validator.VALID) +.required(false) +.build(); +public static final PropertyDescriptor PROJECTION = new PropertyDescriptor.Builder() +.name("mongo-lookup-projection") +.displayName("Projection") +.description("Specifies a projection for limiting which fields will be returned.") +.required(false) +.build(); private String lookupValueField; -private static final List lookupDescriptors; - -static { -lookupDescriptors = new ArrayList<>(); -lookupDescriptors.addAll(descriptors); -lookupDescriptors.add(LOOKUP_VALUE_FIELD); -} - @Override public Optional lookup(Map coordinates) throws LookupFailureException { -Map clean = new HashMap<>(); -clean.putAll(coordinates); +Map clean = coordinates.entrySet().stream() +.filter(e -> !schemaNameProperty.equals(String.format("${%s}", e.getKey( +.collect(Collectors.toMap( +e -> e.getKey(), +e -> e.getValue() +)); Document query = new Document(clean); if (coordinates.size() == 0) { throw new LookupFailureException("No keys were configured. Mongo query would return random documents."); } try { -Document result = this.findOne(query); +Document result = projection != null ? controllerService.findOne(query, projection) : controllerService.findOne(query); if(result == null) { return Optional.empty(); } else if (!StringUtils.isEmpty(lookupValueField)) { return Optional.ofNullable(result.get(lookupValueField)); } else { -final List fields = new ArrayList<>(); +RecordSchema schema = loadSchema(coordinates); -for (String key : result.keySet()) { -if (key.equals("_id")) { -continue; -} -fields.add(new RecordField(key, RecordFieldType.STRING.getDataType())); -} - -final RecordSchema schema = new SimpleRecordSchema(fields); -return Optional.ofNullable(new MapRecord(schema, result)); +RecordSchema toUse = schema != null ? schema : convertSchema(result); +return Optional.ofNullable(new MapRecord(toUse, result)); } } catch (Exception ex) { getLogger().error("Error during lookup {}", new Object[]{ query.toJson() }, ex); throw new LookupFailureException
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r192802068 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() +.name("mongo-lookup-client-service") +.displayName("Client Service") +.description("A MongoDB controller service to use with this lookup service.") +.required(true) +.identifiesControllerService(MongoDBControllerService.class) +.build(); public static final PropertyDescriptor LOOKUP_VALUE_FIELD = new PropertyDescriptor.Builder() -.name("mongo-lookup-value-field") -.displayName("Lookup Value Field") -.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + -"MongoDB result document minus the _id field will be returned as a record.") -.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) -.required(false) -.build(); +.name("mongo-lookup-value-field") +.displayName("Lookup Value Field") +.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + +"MongoDB result document minus the _id field will be returned as a record.") +.addValidator(Validator.VALID) +.required(false) +.build(); +public static final PropertyDescriptor PROJECTION = new PropertyDescriptor.Builder() +.name("mongo-lookup-projection") +.displayName("Projection") +.description("Specifies a projection for limiting which fields will be returned.") +.required(false) +.build(); private String lookupValueField; -private static final List lookupDescriptors; - -static { -lookupDescriptors = new ArrayList<>(); -lookupDescriptors.addAll(descriptors); -lookupDescriptors.add(LOOKUP_VALUE_FIELD); -} - @Override public Optional lookup(Map coordinates) throws LookupFailureException { -Map clean = new HashMap<>(); -clean.putAll(coordinates); +Map clean = coordinates.entrySet().stream() +.filter(e -> !schemaNameProperty.equals(String.format("${%s}", e.getKey( +.collect(Collectors.toMap( +e -> e.getKey(), +e -> e.getValue() +)); Document query = new Document(clean); if (coordinates.size() == 0) { throw new LookupFailureException("No keys were configured. Mongo query would return random documents."); } try { -Document result = this.findOne(query); +Document result = projection != null ? controllerService.findOne(query, projection) : controllerService.findOne(query); if(result == null) { return Optional.empty(); } else if (!StringUtils.isEmpty(lookupValueField)) { return Optional.ofNullable(result.get(lookupValueField)); } else { -final List fields = new ArrayList<>(); +RecordSchema schema = loadSchema(coordinates); -for (String key : result.keySet()) { -if (key.equals("_id")) { -continue; -} -fields.add(new RecordField(key, RecordFieldType.STRING.getDataType())); -} - -final RecordSchema schema = new SimpleRecordSchema(fields); -return Optional.ofNullable(new MapRecord(schema, result)); +RecordSchema toUse = schema != null ? schema : convertSchema(result); +return Optional.ofNullable(new MapRecord(toUse, result)); } } catch (Exception ex) { getLogger().error("Error during lookup {}", new Object[]{ query.toJson() }, ex); throw new LookupFailureExcepti
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r192802039 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() --- End diff -- I added to the property list. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r192784028 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() +.name("mongo-lookup-client-service") +.displayName("Client Service") +.description("A MongoDB controller service to use with this lookup service.") +.required(true) +.identifiesControllerService(MongoDBControllerService.class) +.build(); public static final PropertyDescriptor LOOKUP_VALUE_FIELD = new PropertyDescriptor.Builder() -.name("mongo-lookup-value-field") -.displayName("Lookup Value Field") -.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + -"MongoDB result document minus the _id field will be returned as a record.") -.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) -.required(false) -.build(); +.name("mongo-lookup-value-field") +.displayName("Lookup Value Field") +.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + +"MongoDB result document minus the _id field will be returned as a record.") +.addValidator(Validator.VALID) +.required(false) +.build(); +public static final PropertyDescriptor PROJECTION = new PropertyDescriptor.Builder() +.name("mongo-lookup-projection") +.displayName("Projection") +.description("Specifies a projection for limiting which fields will be returned.") +.required(false) +.build(); private String lookupValueField; -private static final List lookupDescriptors; - -static { -lookupDescriptors = new ArrayList<>(); -lookupDescriptors.addAll(descriptors); -lookupDescriptors.add(LOOKUP_VALUE_FIELD); -} - @Override public Optional lookup(Map coordinates) throws LookupFailureException { -Map clean = new HashMap<>(); -clean.putAll(coordinates); +Map clean = coordinates.entrySet().stream() +.filter(e -> !schemaNameProperty.equals(String.format("${%s}", e.getKey( +.collect(Collectors.toMap( +e -> e.getKey(), +e -> e.getValue() +)); Document query = new Document(clean); if (coordinates.size() == 0) { throw new LookupFailureException("No keys were configured. Mongo query would return random documents."); } try { -Document result = this.findOne(query); +Document result = projection != null ? controllerService.findOne(query, projection) : controllerService.findOne(query); if(result == null) { return Optional.empty(); } else if (!StringUtils.isEmpty(lookupValueField)) { return Optional.ofNullable(result.get(lookupValueField)); } else { -final List fields = new ArrayList<>(); +RecordSchema schema = loadSchema(coordinates); -for (String key : result.keySet()) { -if (key.equals("_id")) { -continue; -} -fields.add(new RecordField(key, RecordFieldType.STRING.getDataType())); -} - -final RecordSchema schema = new SimpleRecordSchema(fields); -return Optional.ofNullable(new MapRecord(schema, result)); +RecordSchema toUse = schema != null ? schema : convertSchema(result); +return Optional.ofNullable(new MapRecord(toUse, result)); } } catch (Exception ex) { getLogger().error("Error during lookup {}", new Object[]{ query.toJson() }, ex); throw new LookupFailureException
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r192783725 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() +.name("mongo-lookup-client-service") +.displayName("Client Service") +.description("A MongoDB controller service to use with this lookup service.") +.required(true) +.identifiesControllerService(MongoDBControllerService.class) --- End diff -- I believe this is supposed to be an interface not the impl class (see my other comment below), so I think you want `MongoDBClientService` here. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r192783531 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() --- End diff -- AFAICT this property is never added to the list of supported property descriptors, so I couldn't set it on the UI which causes an NPE when lookup() is called. Seems odd that for a required property that is not supported, setting it (in tests) would not complain. I haven't run the integration tests yet, just put the NARs into a live NiFi to try it out. ---
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
Github user MikeThomsen commented on a diff in the pull request: https://github.com/apache/nifi/pull/2619#discussion_r189434124 --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -52,68 +54,125 @@ "The query is limited to the first result (findOne in the Mongo documentation). If no \"Lookup Value Field\" is specified " + "then the entire MongoDB result document minus the _id field will be returned as a record." ) -public class MongoDBLookupService extends MongoDBControllerService implements LookupService { +public class MongoDBLookupService extends SchemaRegistryService implements LookupService { +public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() +.name("mongo-lookup-client-service") +.displayName("Client Service") +.description("A MongoDB controller service to use with this lookup service.") +.required(true) +.identifiesControllerService(MongoDBControllerService.class) +.build(); public static final PropertyDescriptor LOOKUP_VALUE_FIELD = new PropertyDescriptor.Builder() -.name("mongo-lookup-value-field") -.displayName("Lookup Value Field") -.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + -"MongoDB result document minus the _id field will be returned as a record.") -.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) -.required(false) -.build(); +.name("mongo-lookup-value-field") +.displayName("Lookup Value Field") +.description("The field whose value will be returned when the lookup key(s) match a record. If not specified then the entire " + +"MongoDB result document minus the _id field will be returned as a record.") +.addValidator(Validator.VALID) +.required(false) +.build(); +public static final PropertyDescriptor PROJECTION = new PropertyDescriptor.Builder() +.name("mongo-lookup-projection") +.displayName("Projection") +.description("Specifies a projection for limiting which fields will be returned.") +.required(false) +.build(); private String lookupValueField; -private static final List lookupDescriptors; - -static { -lookupDescriptors = new ArrayList<>(); -lookupDescriptors.addAll(descriptors); -lookupDescriptors.add(LOOKUP_VALUE_FIELD); -} - @Override public Optional lookup(Map coordinates) throws LookupFailureException { -Map clean = new HashMap<>(); -clean.putAll(coordinates); +Map clean = coordinates.entrySet().stream() +.filter(e -> !schemaNameProperty.equals(String.format("${%s}", e.getKey( +.collect(Collectors.toMap( +e -> e.getKey(), +e -> e.getValue() +)); Document query = new Document(clean); if (coordinates.size() == 0) { throw new LookupFailureException("No keys were configured. Mongo query would return random documents."); } try { -Document result = this.findOne(query); +Document result = projection != null ? controllerService.findOne(query, projection) : controllerService.findOne(query); if(result == null) { return Optional.empty(); } else if (!StringUtils.isEmpty(lookupValueField)) { return Optional.ofNullable(result.get(lookupValueField)); } else { -final List fields = new ArrayList<>(); +RecordSchema schema = loadSchema(coordinates); -for (String key : result.keySet()) { -if (key.equals("_id")) { -continue; -} -fields.add(new RecordField(key, RecordFieldType.STRING.getDataType())); -} - -final RecordSchema schema = new SimpleRecordSchema(fields); -return Optional.ofNullable(new MapRecord(schema, result)); +RecordSchema toUse = schema != null ? schema : convertSchema(result); +return Optional.ofNullable(new MapRecord(toUse, result)); } } catch (Exception ex) { getLogger().error("Error during lookup {}", new Object[]{ query.toJson() }, ex); throw new LookupFailureExcepti
[GitHub] nifi pull request #2619: NIFI-5059 Updated MongoDBLookupService to be able t...
GitHub user MikeThomsen opened a pull request: https://github.com/apache/nifi/pull/2619 NIFI-5059 Updated MongoDBLookupService to be able to detect record sc⦠â¦hemas or take one provided by the user. Thank you for submitting a contribution to Apache NiFi. In order to streamline the review of the contribution we ask you to ensure the following steps have been taken: ### For all changes: - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message? - [ ] Does your PR title start with NIFI- where is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character. - [ ] Has your PR been rebased against the latest commit within the target branch (typically master)? - [ ] Is your initial contribution a single, squashed commit? ### For code changes: - [ ] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder? - [ ] Have you written or updated unit tests to verify your changes? - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly? - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly? - [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties? ### For documentation related changes: - [ ] Have you ensured that format looks appropriate for the output in which it is rendered? ### Note: Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible. You can merge this pull request into a Git repository by running: $ git pull https://github.com/MikeThomsen/nifi NIFI-5059 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/nifi/pull/2619.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #2619 commit 40cbd11915e15e87c5b568a2cd918e57126bb7b4 Author: Mike Thomsen Date: 2018-04-09T11:28:40Z NIFI-5059 Updated MongoDBLookupService to be able to detect record schemas or take one provided by the user. ---