use of org.apache.flink.types.StringValue in project flink by apache.
the class GenericCsvInputFormatTest method readWithHeaderLine.
@Test
public void readWithHeaderLine() {
try {
final String fileContent = "colname-1|colname-2|some name 3|column four|\n" + "123|abc|456|def|\n" + "987|xyz|654|pqr|\n";
final FileInputSplit split = createTempFile(fileContent);
final Configuration parameters = new Configuration();
format.setFieldDelimiter("|");
format.setFieldTypesGeneric(IntValue.class, StringValue.class, IntValue.class, StringValue.class);
format.setSkipFirstLineAsHeader(true);
format.configure(parameters);
format.open(split);
Value[] values = new Value[] { new IntValue(), new StringValue(), new IntValue(), new StringValue() };
// first line is skipped as header
// first row (= second line)
assertNotNull(format.nextRecord(values));
// second row (= third line)
assertNotNull(format.nextRecord(values));
// exhausted
assertNull(format.nextRecord(values));
// exhausted
assertTrue(format.reachedEnd());
} catch (Exception ex) {
fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
}
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class GenericCsvInputFormatTest method readWithEmptyField.
@Test
public void readWithEmptyField() {
try {
final String fileContent = "abc|def|ghijk\nabc||hhg\n|||";
final FileInputSplit split = createTempFile(fileContent);
final Configuration parameters = new Configuration();
format.setFieldDelimiter("|");
format.setFieldTypesGeneric(StringValue.class, StringValue.class, StringValue.class);
format.configure(parameters);
format.open(split);
Value[] values = new Value[] { new StringValue(), new StringValue(), new StringValue() };
values = format.nextRecord(values);
assertNotNull(values);
assertEquals("abc", ((StringValue) values[0]).getValue());
assertEquals("def", ((StringValue) values[1]).getValue());
assertEquals("ghijk", ((StringValue) values[2]).getValue());
values = format.nextRecord(values);
assertNotNull(values);
assertEquals("abc", ((StringValue) values[0]).getValue());
assertEquals("", ((StringValue) values[1]).getValue());
assertEquals("hhg", ((StringValue) values[2]).getValue());
values = format.nextRecord(values);
assertNotNull(values);
assertEquals("", ((StringValue) values[0]).getValue());
assertEquals("", ((StringValue) values[1]).getValue());
assertEquals("", ((StringValue) values[2]).getValue());
} catch (Exception ex) {
fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
}
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class ToNullValueTest method testTranslation.
@Test
public void testTranslation() throws Exception {
NullValue reuse = NullValue.getInstance();
assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new DoubleValue(), reuse));
assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new FloatValue(), reuse));
assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new IntValue(), reuse));
assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new LongValue(), reuse));
assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new StringValue(), reuse));
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class InstantiationUtilTest method testInstantiationOfStringValueAndCastToValue.
@Test
public void testInstantiationOfStringValueAndCastToValue() {
StringValue stringValue = InstantiationUtil.instantiate(StringValue.class, Value.class);
assertNotNull(stringValue);
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class InstantiationUtilTest method testInstantiationOfStringValue.
@Test
public void testInstantiationOfStringValue() {
StringValue stringValue = InstantiationUtil.instantiate(StringValue.class, null);
assertNotNull(stringValue);
}
Aggregations