Github user rickysaltzer commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2020#discussion_r129936165
  
    --- Diff: 
nifi-nar-bundles/nifi-kudu-bundle/nifi-kudu-processors/src/main/java/org/apache/nifi/processors/kudu/AbstractKudu.java
 ---
    @@ -0,0 +1,191 @@
    +/*
    + * 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.kudu;
    +
    +import java.io.BufferedInputStream;
    +import java.io.IOException;
    +import java.io.InputStream;
    +
    +import org.apache.commons.io.IOUtils;
    +import org.apache.kudu.client.KuduClient;
    +import org.apache.kudu.client.KuduException;
    +import org.apache.kudu.client.KuduSession;
    +import org.apache.kudu.client.KuduTable;
    +import org.apache.kudu.client.Insert;
    +
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.flowfile.FlowFile;
    +
    +import org.apache.nifi.processor.AbstractProcessor;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.Relationship;
    +import org.apache.nifi.processor.exception.FlowFileAccessException;
    +import org.apache.nifi.processor.exception.ProcessException;
    +import org.apache.nifi.processor.util.StandardValidators;
    +import 
org.apache.nifi.processors.hadoop.exception.RecordReaderFactoryException;
    +
    +import org.apache.nifi.serialization.RecordReader;
    +import org.apache.nifi.serialization.RecordReaderFactory;
    +import org.apache.nifi.serialization.record.RecordSet;
    +import org.apache.nifi.serialization.record.Record;
    +
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.atomic.AtomicReference;
    +
    +public abstract class AbstractKudu extends AbstractProcessor {
    +
    +    protected static final PropertyDescriptor KUDU_MASTERS = new 
PropertyDescriptor.Builder()
    +            .name("KUDU Masters")
    +            .description("List all kudu masters's ip with port (e.g. 
7051), comma separated")
    +            .required(true)
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +
    +    protected static final PropertyDescriptor TABLE_NAME = new 
PropertyDescriptor.Builder()
    +            .name("Table Name")
    +            .description("The name of the Kudu Table to put data into")
    +            .required(true)
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +
    +    public static final PropertyDescriptor RECORD_READER = new 
PropertyDescriptor.Builder()
    +            .name("record-reader")
    +            .displayName("Record Reader")
    +            .description("The service for reading records from incoming 
flow files.")
    +            .identifiesControllerService(RecordReaderFactory.class)
    +            .required(true)
    +            .build();
    +
    +    protected static final PropertyDescriptor SKIP_HEAD_LINE = new 
PropertyDescriptor.Builder()
    +            .name("Skip head line")
    +            .description("Set it to true if your first line is the header 
line e.g. column names")
    +            .allowableValues("true", "false")
    +            .defaultValue("true")
    +            .required(true)
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +
    +    protected static final Relationship REL_SUCCESS = new 
Relationship.Builder()
    +            .name("success")
    +            .description("A FlowFile is routed to this relationship after 
it has been successfully stored in Kudu")
    +            .build();
    +    protected static final Relationship REL_FAILURE = new 
Relationship.Builder()
    +            .name("failure")
    +            .description("A FlowFile is routed to this relationship if it 
cannot be sent to Kudu")
    +            .build();
    +
    +    public static final String RECORD_COUNT_ATTR = "record.count";
    +
    +    protected String kuduMasters;
    +    protected String tableName;
    +    protected boolean skipHeadLine;
    +
    +    @OnScheduled
    +    public void onScheduled(final ProcessContext context) {
    +        tableName = context.getProperty(TABLE_NAME).getValue();
    +        kuduMasters = context.getProperty(KUDU_MASTERS).getValue();
    +        skipHeadLine = context.getProperty(SKIP_HEAD_LINE).asBoolean();
    +    }
    +
    +    @Override
    +    public void onTrigger(final ProcessContext context, final 
ProcessSession session) throws ProcessException {
    +        final FlowFile flowFile = session.get();
    +        try {
    +            if (flowFile == null) return;
    +            final Map<String,String> attributes = new HashMap<String, 
String>();
    +            final AtomicReference<Throwable> exceptionHolder = new 
AtomicReference<>(null);
    +            final RecordReaderFactory recordReaderFactory = 
context.getProperty(RECORD_READER).asControllerService(RecordReaderFactory.class);
    +            final KuduClient kuduClient = getKuduConnection(kuduMasters);
    +            final KuduTable kuduTable = getKuduTable(kuduClient, 
tableName);
    +            final KuduSession kuduSession = getKuduSession(kuduClient);
    --- End diff --
    
    It would be nice if the user could set our session to ignore duplicate rows 
(e.g. `insert-ignore`) rather than updating / upserting them. A new property 
called `Insert Operation` could have `Insert`, `Insert-Ignore`, and `Upsert`. 
If `Insert-Ignore` is set, then it sets `setIgnoreAllDuplicateRows` when it 
creates the session. Further, if `Upsert` is set, then it creates a new 
`Upsert` operation instead of `Insert`. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to