tpalfy commented on a change in pull request #3611: NIFI-6009 ScanKudu Processor URL: https://github.com/apache/nifi/pull/3611#discussion_r331475213
########## File path: nifi-nar-bundles/nifi-kudu-bundle/nifi-kudu-processors/src/test/java/org/apache/nifi/processors/kudu/TestScanKudu.java ########## @@ -0,0 +1,622 @@ +/* + * 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.math.BigDecimal; +import java.sql.Timestamp; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiConsumer; +import org.apache.kudu.ColumnSchema; +import org.apache.kudu.ColumnTypeAttributes; +import org.apache.kudu.Type; +import org.apache.kudu.client.Insert; +import org.apache.kudu.client.KuduException; +import org.apache.kudu.client.KuduSession; +import org.apache.kudu.client.KuduTable; +import org.apache.kudu.client.PartialRow; +import org.apache.kudu.test.KuduTestHarness; +import org.apache.kudu.test.cluster.MiniKuduCluster; +import org.apache.nifi.reporting.InitializationException; +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class TestScanKudu { Review comment: The binary predicate handling still had a bug. Can we please _really_ cover _**all**_ the cases? Here are some more: ```java @Test public void testPredicateLowerOrEqualsByte() throws Exception { List<Byte> values = Arrays.asList((byte)11, (byte)9, (byte)10, (byte)8); String predicate = "value<=10"; String expectedContent = "[{\"key\":\"2\",\"value\":\"9\"},\n{\"key\":\"3\",\"value\":\"10\"},\n{\"key\":\"4\",\"value\":\"8\"}]"; testPredicate(predicate, expectedContent, Type.INT8, (row, value) -> row.addByte("value", value), values); } @Test public void testPredicateLowerThanShort() throws Exception { List<Short> values = Arrays.asList((short)11, (short)9, (short)10, (short)-8); String predicate = "value<10"; String expectedContent = "[{\"key\":\"2\",\"value\":\"9\"},\n{\"key\":\"4\",\"value\":\"-8\"}]"; testPredicate(predicate, expectedContent, Type.INT16, (row, value) -> row.addShort("value", value), values); } @Test public void testPredicateEqualsLong() throws Exception { List<Long> values = Arrays.asList(11L, 9L, 10L, 8L); String predicate = "value=10"; String expectedContent = "[{\"key\":\"3\",\"value\":\"10\"}]"; testPredicate(predicate, expectedContent, Type.INT64, (row, value) -> row.addLong("value", value), values); } @Test public void testPredicatesEqualsBinary() throws Exception { List<byte[]> values = Arrays.asList( new byte[] {127, 10, 28}, new byte[] {-128, 10, 28}, new byte[] {0, 10, 28} ); String predicate = "value=7f0a1c"; String expectedContent = "[{\"key\":\"1\",\"value\":\"7f0a1c\"}]"; testPredicate(predicate, expectedContent, Type.BINARY, (row, value) -> row.addBinary("value", value), values); } @Test public void testPredicateGreaterOrEqualsBigDecimal() throws Exception { List<BigDecimal> values = Arrays.asList( new BigDecimal("15643691156541351512356.1264865416"), new BigDecimal("69879841523159494156164.3198491561316"), new BigDecimal("99165198489191894987456.61561616") ); String predicate = "value>=69879841523159494156164.3198491561316"; String expectedContent = "[{\"key\":\"2\",\"value\":\"69879841523159494156164.3198491561316\"},\n" + "{\"key\":\"3\",\"value\":\"99165198489191894987456.6156161600000\"}]"; testPredicate( predicate, expectedContent, new ColumnSchema.ColumnSchemaBuilder("value", Type.DECIMAL).key(false).typeAttributes( new ColumnTypeAttributes.ColumnTypeAttributesBuilder() .precision(38) .scale(13) .build() ).build(), (row, value) -> row.addDecimal("value", value), values ); } ... private <V> void testPredicate(String predicate, String expectedContent, Type valueType, BiConsumer<PartialRow, V> valueSetter, List<V> values) throws Exception { testPredicate( predicate, expectedContent, new ColumnSchema.ColumnSchemaBuilder("value", valueType).key(false).build(), valueSetter, values ); } private <V> void testPredicate(String predicate, String expectedContent, ColumnSchema valueColumnSchema, BiConsumer<PartialRow, V> valueSetter, List<V> values) throws Exception { List<ColumnSchema> columns = Arrays.asList( new ColumnSchema.ColumnSchemaBuilder("key", Type.INT32).key(true).build(), valueColumnSchema ); ... ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to 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
