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))));
}
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));
}
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());
}
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());
}
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());
}
Aggregations