Search in sources :

Example 6 with TupleBuilder

use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.

the class TestTupleBuilder method testYellowTaxiRangeTupleBuilder.

/**
 * Test the yellow taxi range tuple builder
 * @throws ParseException
 */
@Test
public void testYellowTaxiRangeTupleBuilder() throws ParseException {
    final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.YELLOWTAXI_RANGE);
    final Tuple tuple = tupleBuilder.buildTuple("1", TAXI_TEST_LINE);
    Assert.assertTrue(tuple != null);
    Assert.assertEquals(Integer.toString(1), tuple.getKey());
    final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
    final Date dateLow = dateParser.parse("2016-01-01 00:00:00");
    final Date dateHigh = dateParser.parse("2016-01-01 00:00:00");
    final BoundingBox exptectedBox = new BoundingBox(-73.990371704101563, -73.981842041015625, 40.732406616210937, 40.734695434570313, (double) dateLow.getTime(), (double) dateHigh.getTime());
    Assert.assertEquals(exptectedBox, tuple.getBoundingBox());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) BoundingBox(org.bboxdb.commons.math.BoundingBox) SimpleDateFormat(java.text.SimpleDateFormat) Tuple(org.bboxdb.storage.entity.Tuple) Date(java.util.Date) Test(org.junit.Test)

Example 7 with TupleBuilder

use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.

the class TestTupleBuilder method testTupleFile2.

/**
 * Test the tuple file builder
 * @throws IOException
 */
@Test
public void testTupleFile2() 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.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();
    Assert.assertEquals(1, seenTuples.get());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileWriter(java.io.FileWriter) TupleFileReader(org.bboxdb.tools.TupleFileReader) File(java.io.File) Tuple(org.bboxdb.storage.entity.Tuple) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 8 with TupleBuilder

use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.

the class TestTupleBuilder method testYellowTaxiPointTupleBuilder.

/**
 * Test the yellow taxi range tuple builder
 * @throws ParseException
 */
@Test
public void testYellowTaxiPointTupleBuilder() throws ParseException {
    final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.YELLOWTAXI_POINT);
    final Tuple tuple = tupleBuilder.buildTuple("1", TAXI_TEST_LINE);
    Assert.assertTrue(tuple != null);
    Assert.assertEquals(Integer.toString(1), tuple.getKey());
    final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
    final Date dateLow = dateParser.parse("2016-01-01 00:00:00");
    final BoundingBox exptectedBox = new BoundingBox(-73.990371704101563, -73.990371704101563, 40.734695434570313, 40.734695434570313, (double) dateLow.getTime(), (double) dateLow.getTime());
    Assert.assertEquals(exptectedBox, tuple.getBoundingBox());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) BoundingBox(org.bboxdb.commons.math.BoundingBox) SimpleDateFormat(java.text.SimpleDateFormat) Tuple(org.bboxdb.storage.entity.Tuple) Date(java.util.Date) Test(org.junit.Test)

Example 9 with TupleBuilder

use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.

the class TestTupleBuilder method testTPCHLineitemPointTupleBuilder.

/**
 * Test the tpch point tuple builder
 * @throws ParseException
 */
@Test
public void testTPCHLineitemPointTupleBuilder() throws ParseException {
    final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.TPCH_LINEITEM_POINT);
    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 date = dateParser.parse("1993-12-04");
    final double doubleTime = (double) date.getTime();
    final BoundingBox exptectedBox = new BoundingBox(doubleTime, doubleTime);
    Assert.assertEquals(exptectedBox, tuple.getBoundingBox());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) BoundingBox(org.bboxdb.commons.math.BoundingBox) SimpleDateFormat(java.text.SimpleDateFormat) Tuple(org.bboxdb.storage.entity.Tuple) Date(java.util.Date) Test(org.junit.Test)

Example 10 with TupleBuilder

use of org.bboxdb.tools.converter.tuple.TupleBuilder in project bboxdb by jnidzwetzki.

the class TestTupleBuilder method testTupleFile4.

/**
 * Test the tuple file builder - Read 5 of 3 lines
 * @throws IOException
 */
@Test
public void testTupleFile4() 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.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.getBoundingBox(), t.getBoundingBox());
        Assert.assertArrayEquals(tuple.getDataBytes(), t.getDataBytes());
        seenTuples.incrementAndGet();
    });
    tupleFile.processFile(3);
    Assert.assertEquals(3, seenTuples.get());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileWriter(java.io.FileWriter) TupleFileReader(org.bboxdb.tools.TupleFileReader) File(java.io.File) Tuple(org.bboxdb.storage.entity.Tuple) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Aggregations

Tuple (org.bboxdb.storage.entity.Tuple)11 TupleBuilder (org.bboxdb.tools.converter.tuple.TupleBuilder)11 Test (org.junit.Test)10 BoundingBox (org.bboxdb.commons.math.BoundingBox)8 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 BufferedWriter (java.io.BufferedWriter)3 File (java.io.File)3 FileWriter (java.io.FileWriter)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 TupleFileReader (org.bboxdb.tools.TupleFileReader)3 RandomAccessFile (java.io.RandomAccessFile)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1