use of org.apache.flink.types.IntValue in project flink by apache.
the class IntValueComparator method compareToReference.
@Override
public int compareToReference(TypeComparator<IntValue> referencedComparator) {
IntValue otherRef = ((IntValueComparator) referencedComparator).reference;
int comp = otherRef.compareTo(reference);
return ascendingComparison ? comp : -comp;
}
use of org.apache.flink.types.IntValue 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.IntValue in project flink by apache.
the class GenericCsvInputFormatTest method testReadInvalidContents.
@Test
public void testReadInvalidContents() throws IOException {
try {
final String fileContent = "abc|222|def|444\nkkz|777|888|hhg";
final FileInputSplit split = createTempFile(fileContent);
final Configuration parameters = new Configuration();
format.setFieldDelimiter("|");
format.setFieldTypesGeneric(StringValue.class, IntValue.class, StringValue.class, IntValue.class);
format.configure(parameters);
format.open(split);
Value[] values = new Value[] { new StringValue(), new IntValue(), new StringValue(), new IntValue() };
assertNotNull(format.nextRecord(values));
try {
format.nextRecord(values);
fail("Input format accepted on invalid input.");
} catch (ParseException ignored) {
}
} catch (Exception ex) {
fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
}
}
use of org.apache.flink.types.IntValue in project flink by apache.
the class GenericCsvInputFormatTest method testReadNoPosAllDeflate.
@Test
public void testReadNoPosAllDeflate() throws IOException {
try {
final String fileContent = "111|222|333|444|555\n666|777|888|999|000|";
final FileInputSplit split = createTempDeflateFile(fileContent);
final Configuration parameters = new Configuration();
format.setFieldDelimiter("|");
format.setFieldTypesGeneric(IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
format.configure(parameters);
format.open(split);
Value[] values = createIntValues(5);
values = format.nextRecord(values);
assertNotNull(values);
assertEquals(111, ((IntValue) values[0]).getValue());
assertEquals(222, ((IntValue) values[1]).getValue());
assertEquals(333, ((IntValue) values[2]).getValue());
assertEquals(444, ((IntValue) values[3]).getValue());
assertEquals(555, ((IntValue) values[4]).getValue());
values = format.nextRecord(values);
assertNotNull(values);
assertEquals(666, ((IntValue) values[0]).getValue());
assertEquals(777, ((IntValue) values[1]).getValue());
assertEquals(888, ((IntValue) values[2]).getValue());
assertEquals(999, ((IntValue) values[3]).getValue());
assertEquals(000, ((IntValue) values[4]).getValue());
assertNull(format.nextRecord(values));
assertTrue(format.reachedEnd());
} catch (Exception ex) {
fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
}
}
use of org.apache.flink.types.IntValue in project flink by apache.
the class GenericCsvInputFormatTest method testSparseParse.
@Test
public void testSparseParse() {
try {
final String fileContent = "111|222|333|444|555|666|777|888|999|000|\n" + "000|999|888|777|666|555|444|333|222|111|";
final FileInputSplit split = createTempFile(fileContent);
final Configuration parameters = new Configuration();
format.setFieldDelimiter("|");
format.setFieldTypesGeneric(IntValue.class, null, null, IntValue.class, null, null, null, IntValue.class);
format.configure(parameters);
format.open(split);
Value[] values = createIntValues(3);
values = format.nextRecord(values);
assertNotNull(values);
assertEquals(111, ((IntValue) values[0]).getValue());
assertEquals(444, ((IntValue) values[1]).getValue());
assertEquals(888, ((IntValue) values[2]).getValue());
values = format.nextRecord(values);
assertNotNull(values);
assertEquals(000, ((IntValue) values[0]).getValue());
assertEquals(777, ((IntValue) values[1]).getValue());
assertEquals(333, ((IntValue) values[2]).getValue());
assertNull(format.nextRecord(values));
assertTrue(format.reachedEnd());
} catch (Exception ex) {
System.err.println(ex.getMessage());
ex.printStackTrace();
fail("Test erroneous");
}
}
Aggregations