use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TestTupleBuilder method testTPCHLineitemRangeTupleBuilder.
/**
* Test the tpch range tuple builder
* @throws ParseException
*/
@Test
public void testTPCHLineitemRangeTupleBuilder() throws ParseException {
final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.TPCH_LINEITEM_RANGE);
final Tuple tuple = tupleBuilder.buildTuple("1", TPCH_LINEITEM_TEST_LINE);
Assert.assertTrue(tuple != null);
Assert.assertEquals(Integer.toString(1), tuple.getKey());
final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-mm-dd");
final Date shipDateTime = dateParser.parse("1993-12-04");
final Date receiptDateTime = dateParser.parse("1994-01-01");
final double doubleShipDateTime = (double) shipDateTime.getTime();
final double doublereceiptDateTime = (double) receiptDateTime.getTime();
final BoundingBox exptectedBox = new BoundingBox(doubleShipDateTime, doublereceiptDateTime);
Assert.assertEquals(exptectedBox, tuple.getBoundingBox());
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TestTupleBuilder method testTPCHOrderPointTupleBuilder.
/**
* Test the tpch range tuple builder
* @throws ParseException
*/
@Test
public void testTPCHOrderPointTupleBuilder() throws ParseException {
final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.TPCH_ORDER_POINT);
final Tuple tuple = tupleBuilder.buildTuple("1", TPCH_ORDER_TEST_LINE);
Assert.assertTrue(tuple != null);
Assert.assertEquals(Integer.toString(1), tuple.getKey());
final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-mm-dd");
final Date orderDate = dateParser.parse("1996-01-02");
final double doubleOrder = (double) orderDate.getTime();
final BoundingBox expectedBox = new BoundingBox(doubleOrder, doubleOrder);
Assert.assertEquals(expectedBox, tuple.getBoundingBox());
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TestTupleBuilder method testTupleFile3.
/**
* Test the tuple file builder
* @throws IOException
*/
@Test
public void testTupleFile3() throws IOException {
final File tempFile = File.createTempFile("temp", ".txt");
tempFile.deleteOnExit();
// The reference tuple
final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.GEOJSON);
final Tuple tuple = tupleBuilder.buildTuple("1", GEO_JSON_LINE);
final BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
writer.write(GEO_JSON_LINE);
writer.write("\n");
writer.write(GEO_JSON_LINE);
writer.write("\n");
writer.close();
final TupleFileReader tupleFile = new TupleFileReader(tempFile.getAbsolutePath(), TupleBuilderFactory.Name.GEOJSON);
final AtomicInteger seenTuples = new AtomicInteger(0);
tupleFile.addTupleListener(t -> {
Assert.assertEquals(tuple.getKey(), t.getKey());
Assert.assertEquals(tuple.getBoundingBox(), t.getBoundingBox());
Assert.assertArrayEquals(tuple.getDataBytes(), t.getDataBytes());
seenTuples.incrementAndGet();
});
tupleFile.processFile(1);
Assert.assertEquals(1, seenTuples.get());
Assert.assertEquals(2, tupleFile.getProcessedLines());
Assert.assertEquals(GEO_JSON_LINE, tupleFile.getLastReadLine());
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TestTupleBuilder method testGeoJsonTupleBuilder.
/**
* Test the geo json tuple builder
*/
@Test
public void testGeoJsonTupleBuilder() {
final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.GEOJSON);
final Tuple tuple = tupleBuilder.buildTuple("1", GEO_JSON_LINE);
Assert.assertTrue(tuple != null);
Assert.assertEquals(Integer.toString(1), tuple.getKey());
final BoundingBox expectedBox = new BoundingBox(52.4688608, 52.4688608, 13.3327994, 13.3327994);
Assert.assertEquals(expectedBox, tuple.getBoundingBox());
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TPCHOrderPointBuilder method buildTuple.
@Override
public // 1|738001|O|215050.73|1996-01-02|5-LOW|Clerk#000019011|0|nstructions sleep furiously among |
Tuple buildTuple(final String keyData, final String valueData) {
final String[] data = valueData.split("\\|");
try {
final Date orderDate = dateParser.parse(data[4]);
final double orderDateTime = (double) orderDate.getTime();
final BoundingBox boundingBox = new BoundingBox(orderDateTime, orderDateTime);
final Tuple tuple = new Tuple(keyData, boundingBox, valueData.getBytes());
return tuple;
} catch (ParseException e) {
logger.error("Unabe to parse: ", e);
return null;
}
}
Aggregations