Search in sources :

Example 61 with Arrays.asList

use of java.util.Arrays.asList in project flink by apache.

the class DataStructureConvertersTest method testData.

@Parameters(name = "{index}: {0}")
public static List<TestSpec> testData() {
    // ordered by definition in DataStructureConverters
    return asList(TestSpec.forDataType(CHAR(5)).convertedTo(String.class, "12345").convertedTo(byte[].class, "12345".getBytes(StandardCharsets.UTF_8)).convertedTo(StringData.class, StringData.fromString("12345")), TestSpec.forDataType(VARCHAR(100)).convertedTo(String.class, "12345").convertedTo(byte[].class, "12345".getBytes(StandardCharsets.UTF_8)).convertedTo(StringData.class, StringData.fromString("12345")), TestSpec.forDataType(BOOLEAN().notNull()).convertedTo(Boolean.class, true).convertedTo(boolean.class, true), TestSpec.forDataType(BINARY(5)).convertedTo(byte[].class, new byte[] { 1, 2, 3, 4, 5 }), TestSpec.forDataType(VARBINARY(100)).convertedTo(byte[].class, new byte[] { 1, 2, 3, 4, 5 }), TestSpec.forDataType(DECIMAL(3, 2)).convertedTo(BigDecimal.class, new BigDecimal("1.23")).convertedTo(DecimalData.class, DecimalData.fromUnscaledLong(123, 3, 2)), TestSpec.forDataType(DATE()).convertedTo(Date.class, Date.valueOf("2010-11-12")).convertedTo(LocalDate.class, LocalDate.parse("2010-11-12")).convertedTo(Integer.class, 14_925), TestSpec.forDataType(TIME(0)).convertedTo(java.sql.Time.class, java.sql.Time.valueOf("12:34:56")).convertedTo(LocalTime.class, LocalTime.parse("12:34:56")).convertedTo(Integer.class, 45_296_000).convertedTo(Long.class, 45_296_000_000_000L), // TODO support precision of 9
    TestSpec.forDataType(TIME(3)).convertedTo(LocalTime.class, LocalTime.parse("12:34:56.001")).convertedTo(Integer.class, 45_296_001), TestSpec.forDataType(TIMESTAMP(9)).convertedTo(Timestamp.class, Timestamp.valueOf("2010-11-12 12:34:56.000000001")).convertedTo(LocalDateTime.class, LocalDateTime.parse("2010-11-12T12:34:56.000000001")).convertedTo(TimestampData.class, TimestampData.fromEpochMillis(1_289_565_296_000L, 1)), TestSpec.forDataType(TIMESTAMP_WITH_TIME_ZONE(0)).convertedTo(ZonedDateTime.class, ZonedDateTime.ofInstant(Instant.EPOCH, ZoneId.of("UTC"))).convertedTo(java.time.OffsetDateTime.class, ZonedDateTime.ofInstant(Instant.EPOCH, ZoneId.of("UTC")).toOffsetDateTime()).expectErrorMessage("Unsupported data type: TIMESTAMP(0) WITH TIME ZONE"), TestSpec.forDataType(TIMESTAMP_WITH_LOCAL_TIME_ZONE(0)).convertedTo(Instant.class, Instant.ofEpochSecond(12_345)).convertedTo(Integer.class, 12_345).convertedTo(Long.class, 12_345_000L).convertedTo(java.sql.Timestamp.class, new Timestamp(12_345_000L)).convertedTo(TimestampData.class, TimestampData.fromEpochMillis(12_345_000)), TestSpec.forDataType(TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)).convertedTo(Instant.class, Instant.ofEpochSecond(12_345, 1_000_000)).convertedTo(Long.class, 12_345_001L).convertedTo(java.sql.Timestamp.class, new Timestamp(12_345_001L)).convertedTo(TimestampData.class, TimestampData.fromEpochMillis(12_345_001)), TestSpec.forDataType(TIMESTAMP_WITH_LOCAL_TIME_ZONE(9)).convertedTo(Instant.class, Instant.ofEpochSecond(12_345, 1)).convertedTo(TimestampData.class, TimestampData.fromEpochMillis(12_345_000, 1)), TestSpec.forDataType(INTERVAL(YEAR(2), MONTH())).convertedTo(Period.class, Period.of(2, 6, 0)).convertedTo(Integer.class, 30), TestSpec.forDataType(INTERVAL(MONTH())).convertedTo(Period.class, Period.of(0, 30, 0)).convertedTo(Integer.class, 30), // TODO support precision of 9
    TestSpec.forDataType(INTERVAL(DAY(), SECOND(3))).convertedTo(Duration.class, Duration.ofMillis(123)).convertedTo(Long.class, 123L), TestSpec.forDataType(ARRAY(BOOLEAN().notNull())).convertedTo(boolean[].class, new boolean[] { true, false, true, true }).convertedTo(ArrayData.class, new GenericArrayData(new boolean[] { true, false, true, true })), TestSpec.forDataType(ARRAY(BOOLEAN())).convertedTo(Boolean[].class, new Boolean[] { true, null, true, true }).convertedTo(List.class, Arrays.asList(true, null, true, true)).convertedTo(ArrayData.class, new GenericArrayData(new Boolean[] { true, null, true, true })), TestSpec.forDataType(// int.class should not
    ARRAY(INT().notNull().bridgedTo(int.class))).convertedTo(int[].class, new int[] { 1, 2, 3, 4 }).convertedTo(Integer[].class, new Integer[] { 1, 2, 3, 4 }).convertedTo(List.class, new LinkedList<>(Arrays.asList(1, 2, 3, // test List that is not backed by an array
    4))), TestSpec.forDataType(ARRAY(DATE())).convertedTo(LocalDate[].class, new LocalDate[] { null, LocalDate.parse("2010-11-12"), null, LocalDate.parse("2010-11-12") }).convertedTo(List.class, Arrays.asList(null, LocalDate.parse("2010-11-12"), null, LocalDate.parse("2010-11-12"))), TestSpec.forDataType(MAP(INT().bridgedTo(int.class), // int.class should not have an impact
    BOOLEAN())).convertedTo(Map.class, createIdentityMap()).convertedTo(MapData.class, new GenericMapData(createIdentityMap())), TestSpec.forDataType(MAP(DATE(), BOOLEAN())).convertedTo(Map.class, createLocalDateMap()), TestSpec.forDataType(MULTISET(BOOLEAN())).convertedTo(Map.class, createIdentityMultiset()).convertedTo(MapData.class, new GenericMapData(createIdentityMultiset())), TestSpec.forDataType(MULTISET(DATE())).convertedTo(Map.class, createLocalDateMultiset()), TestSpec.forDataType(ROW(FIELD("a", INT()), FIELD("b", ROW(FIELD("b_1", DOUBLE()), FIELD("b_2", BOOLEAN()))))).convertedTo(Row.class, Row.ofKind(RowKind.DELETE, 12, Row.of(2.0, null))).convertedToSupplier(Row.class, () -> {
        final Row namedRow = Row.withNames(RowKind.DELETE);
        namedRow.setField("a", 12);
        final Row sparseNamedRow = Row.withNames();
        // "b_2" is omitted
        sparseNamedRow.setField("b_1", 2.0);
        namedRow.setField("b", sparseNamedRow);
        return namedRow;
    }).convertedTo(RowData.class, GenericRowData.ofKind(RowKind.DELETE, 12, GenericRowData.of(2.0, null))), TestSpec.forDataType(ROW(FIELD("a", INT()), FIELD("b", ROW(FIELD("b_1", DATE()), FIELD("b_2", DATE()))))).convertedTo(Row.class, Row.of(12, Row.of(LocalDate.ofEpochDay(1), null))), TestSpec.forClass(PojoWithMutableFields.class).convertedToSupplier(PojoWithMutableFields.class, () -> {
        final PojoWithMutableFields pojo = new PojoWithMutableFields();
        pojo.age = 42;
        pojo.name = "Bob";
        return pojo;
    }).convertedTo(Row.class, Row.of(42, "Bob")).convertedTo(RowData.class, GenericRowData.of(42, StringData.fromString("Bob"))), TestSpec.forClass(PojoWithImmutableFields.class).convertedTo(PojoWithImmutableFields.class, new PojoWithImmutableFields(42, "Bob")).convertedTo(Row.class, Row.of(42, "Bob")).convertedTo(RowData.class, GenericRowData.of(42, StringData.fromString("Bob"))), TestSpec.forClass(PojoWithGettersAndSetters.class).convertedToSupplier(PojoWithGettersAndSetters.class, () -> {
        final PojoWithGettersAndSetters pojo = new PojoWithGettersAndSetters();
        pojo.setAge(42);
        pojo.setName("Bob");
        return pojo;
    }).convertedTo(Row.class, Row.of(42, "Bob")).convertedTo(RowData.class, GenericRowData.of(42, StringData.fromString("Bob"))), TestSpec.forClass(ComplexPojo.class).convertedToSupplier(ComplexPojo.class, () -> {
        final ComplexPojo pojo = new ComplexPojo();
        pojo.setTimestamp(Timestamp.valueOf("2010-11-12 13:14:15.000000001"));
        pojo.setPreferences(Row.of(42, "Bob", new Boolean[] { true, null, false }));
        pojo.setBalance(new BigDecimal("1.23"));
        return pojo;
    }).convertedTo(Row.class, Row.of(Timestamp.valueOf("2010-11-12 13:14:15.000000001"), Row.of(42, "Bob", new Boolean[] { true, null, false }), new BigDecimal("1.23"))), TestSpec.forClass(PojoAsSuperclass.class).convertedToSupplier(PojoWithMutableFields.class, () -> {
        final PojoWithMutableFields pojo = new PojoWithMutableFields();
        pojo.age = 42;
        pojo.name = "Bob";
        return pojo;
    }).convertedTo(Row.class, Row.of(42)), TestSpec.forDataType(MAP(STRING(), DataTypes.of(PojoWithImmutableFields.class))).convertedTo(Map.class, createPojoWithImmutableFieldsMap()), TestSpec.forDataType(ARRAY(DataTypes.of(PojoWithNestedPojo.class))).convertedTo(PojoWithNestedPojo[].class, createPojoWithNestedPojoArray()).convertedTo(Row[].class, new Row[] { Row.of(new PojoWithImmutableFields(42, "Bob"), new PojoWithImmutableFields[] { new PojoWithImmutableFields(42, "Bob"), null }), null, Row.of(null, new PojoWithImmutableFields[3]), Row.of(null, null) }).convertedToWithAnotherValue(Row[].class, new Row[] { Row.of(null, null), Row.of(new PojoWithImmutableFields(10, "Bob"), null) }), TestSpec.forDataType(DataTypes.of(PojoWithList.class)).convertedTo(PojoWithList.class, new PojoWithList(Arrays.asList(Arrays.asList(1.0, null, 2.0, null), Collections.emptyList(), null))).convertedTo(Row.class, Row.of(Arrays.asList(Arrays.asList(1.0, null, 2.0, null), Collections.emptyList(), null))), TestSpec.forDataType(DataTypes.STRUCTURED(GenericPojo.class, FIELD("value", INT()))).convertedTo(GenericPojo.class, new GenericPojo<>(12)), TestSpec.forDataType(DataTypes.STRUCTURED(GenericPojo.class, FIELD("value", DATE()))).convertedTo(GenericPojo.class, new GenericPojo<>(LocalDate.ofEpochDay(123))));
}
Also used : Timestamp(java.sql.Timestamp) LocalDate(java.time.LocalDate) ZonedDateTime(java.time.ZonedDateTime) Arrays.asList(java.util.Arrays.asList) List(java.util.List) LinkedList(java.util.LinkedList) LocalTime(java.time.LocalTime) Instant(java.time.Instant) BigDecimal(java.math.BigDecimal) LocalDate(java.time.LocalDate) Date(java.sql.Date) LinkedList(java.util.LinkedList) Row(org.apache.flink.types.Row) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Parameters(org.junit.runners.Parameterized.Parameters)

Example 62 with Arrays.asList

use of java.util.Arrays.asList in project pentaho-kettle by pentaho.

the class FixedTimeStreamWindowTest method resultsComeBackToParent.

@Test
public void resultsComeBackToParent() throws KettleException {
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("field"));
    Result mockResult = new Result();
    mockResult.setRows(Arrays.asList(new RowMetaAndData(rowMeta, "queen"), new RowMetaAndData(rowMeta, "king")));
    when(subtransExecutor.execute(any())).thenReturn(Optional.of(mockResult));
    when(subtransExecutor.getPrefetchCount()).thenReturn(10);
    FixedTimeStreamWindow<List> window = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 2, 1);
    window.buffer(Flowable.fromIterable(singletonList(asList("v1", "v2")))).forEach(result -> assertEquals(mockResult, result));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 63 with Arrays.asList

use of java.util.Arrays.asList in project pentaho-kettle by pentaho.

the class FixedTimeStreamWindowTest method emptyResultsNotPostProcessed.

@Test
public void emptyResultsNotPostProcessed() throws KettleException {
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("field"));
    Result mockResult = new Result();
    mockResult.setRows(Arrays.asList(new RowMetaAndData(rowMeta, "queen"), new RowMetaAndData(rowMeta, "king")));
    when(subtransExecutor.execute(any())).thenReturn(Optional.empty());
    when(subtransExecutor.getPrefetchCount()).thenReturn(10);
    AtomicInteger count = new AtomicInteger();
    FixedTimeStreamWindow<List> window = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 2, 1, (p) -> count.set(p.getKey().get(0).size()));
    window.buffer(Flowable.fromIterable(singletonList(asList("v1", "v2")))).forEach(result -> assertEquals(mockResult, result));
    assertEquals(0, count.get());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 64 with Arrays.asList

use of java.util.Arrays.asList in project pentaho-kettle by pentaho.

the class FixedTimeStreamWindowTest method testSharedStreamingBatchPoolExecution.

@Test
public void testSharedStreamingBatchPoolExecution() throws Exception {
    /*
    * Tests that there is only 1 thread running inside the pool at all times.
    * */
    final List<String> errors = new ArrayList<String>();
    // Only 1 thread should be present in the pool at a given time.
    System.setProperty(Const.SHARED_STREAMING_BATCH_POOL_SIZE, "1");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("field"));
    Result mockResult = new Result();
    mockResult.setRows(Arrays.asList(new RowMetaAndData(rowMeta, "queen"), new RowMetaAndData(rowMeta, "king")));
    FixedTimeStreamWindow<List> window1 = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 10, 10);
    FixedTimeStreamWindow<List> window2 = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 10, 10);
    Flowable flowable = Flowable.fromIterable(singletonList(asList("v1", "v2")));
    Field field = window1.getClass().getDeclaredField("sharedStreamingBatchPool");
    field.setAccessible(true);
    ThreadPoolExecutor sharedStreamingBatchPool = (ThreadPoolExecutor) field.get(window1);
    when(subtransExecutor.getPrefetchCount()).thenReturn(1000);
    when(subtransExecutor.execute(any())).thenAnswer((InvocationOnMock invocation) -> {
        // The active count should always be 1.
        if (sharedStreamingBatchPool.getActiveCount() != 1) {
            errors.add("Error: Active count should have been 1 at all times. Current value: " + sharedStreamingBatchPool.getActiveCount());
        }
        return Optional.of(mockResult);
    });
    Thread bufferThread1 = new Thread(new BufferThread(window1, flowable, mockResult));
    bufferThread1.start();
    Thread bufferThread2 = new Thread(new BufferThread(window2, flowable, mockResult));
    bufferThread2.start();
    Thread.sleep(10000);
    assertEquals(0, errors.size());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) BaseMessages.getString(org.pentaho.di.i18n.BaseMessages.getString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Result(org.pentaho.di.core.Result) Field(java.lang.reflect.Field) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Flowable(io.reactivex.Flowable) Test(org.junit.Test)

Example 65 with Arrays.asList

use of java.util.Arrays.asList in project pentaho-kettle by pentaho.

the class FixedTimeStreamWindowTest method supportsPostProcessing.

@Test
public void supportsPostProcessing() throws KettleException {
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("field"));
    Result mockResult = new Result();
    mockResult.setRows(Arrays.asList(new RowMetaAndData(rowMeta, "queen"), new RowMetaAndData(rowMeta, "king")));
    when(subtransExecutor.execute(any())).thenReturn(Optional.of(mockResult));
    when(subtransExecutor.getPrefetchCount()).thenReturn(10);
    AtomicInteger count = new AtomicInteger();
    FixedTimeStreamWindow<List> window = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 2, 1, (p) -> count.set(p.getKey().get(0).size()));
    window.buffer(Flowable.fromIterable(singletonList(asList("v1", "v2")))).forEach(result -> assertEquals(mockResult, result));
    assertEquals(2, count.get());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Aggregations

Arrays.asList (java.util.Arrays.asList)65 List (java.util.List)61 ArrayList (java.util.ArrayList)48 Test (org.junit.Test)32 Arrays (java.util.Arrays)19 Collections.singletonList (java.util.Collections.singletonList)18 Map (java.util.Map)15 Test (org.junit.jupiter.api.Test)15 HashMap (java.util.HashMap)14 Collection (java.util.Collection)12 Collectors (java.util.stream.Collectors)12 Method (java.lang.reflect.Method)9 Optional (java.util.Optional)9 Collections.emptyList (java.util.Collections.emptyList)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 Collections (java.util.Collections)7 Employee (com.artezio.arttime.datamodel.Employee)6 HourType (com.artezio.arttime.datamodel.HourType)6 Hours (com.artezio.arttime.datamodel.Hours)6 Project (com.artezio.arttime.datamodel.Project)6