Search in sources :

Example 91 with Tuple

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());
}
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 92 with Tuple

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());
}
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 93 with Tuple

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());
}
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 94 with Tuple

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());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) BoundingBox(org.bboxdb.commons.math.BoundingBox) Tuple(org.bboxdb.storage.entity.Tuple) Test(org.junit.Test)

Example 95 with Tuple

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;
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) ParseException(java.text.ParseException) Date(java.util.Date) Tuple(org.bboxdb.storage.entity.Tuple)

Aggregations

Tuple (org.bboxdb.storage.entity.Tuple)198 Test (org.junit.Test)123 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)104 BoundingBox (org.bboxdb.commons.math.BoundingBox)62 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)58 ArrayList (java.util.ArrayList)41 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)25 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)24 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)18 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)18 ByteBuffer (java.nio.ByteBuffer)17 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)15 SSTableKeyIndexReader (org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader)13 IOException (java.io.IOException)11 List (java.util.List)11 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)11 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)11 StorageManagerException (org.bboxdb.storage.StorageManagerException)11 TupleBuilder (org.bboxdb.tools.converter.tuple.TupleBuilder)11