Search in sources :

Example 1 with TupleBuilder

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

the class ExperimentStatistics method getSplit.

/**
 * Take a certain number of samples and generate a split position
 * @param sampleSize
 * @param numberOfElements
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
protected double getSplit(final float sampleSize, final long numberOfElements) throws ClassNotFoundException, IOException {
    final Set<Long> takenSamples = new HashSet<>();
    final List<BoundingBox> samples = new ArrayList<>();
    final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(format);
    try (final RandomAccessFile randomAccessFile = new RandomAccessFile(filename, "r")) {
        while (takenSamples.size() < sampleSize) {
            final long sampleId = ThreadLocalRandom.current().nextLong(numberOfElements);
            if (takenSamples.contains(sampleId)) {
                continue;
            }
            // Line 1 is sample 0 in the file
            final long pos = fli.locateLine(sampleId + 1);
            randomAccessFile.seek(pos);
            final String line = randomAccessFile.readLine();
            final Tuple tuple = tupleBuilder.buildTuple(Long.toString(sampleId), line);
            // E.g. Table header
            if (tuple == null) {
                continue;
            }
            final BoundingBox boundingBox = tuple.getBoundingBox();
            samples.add(boundingBox);
            tupleDimension = boundingBox.getDimension();
            takenSamples.add(sampleId);
        }
    }
    samples.sort((b1, b2) -> Double.compare(b1.getCoordinateLow(0), b2.getCoordinateLow(0)));
    return samples.get(samples.size() / 2).getCoordinateLow(0);
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) RandomAccessFile(java.io.RandomAccessFile) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) Tuple(org.bboxdb.storage.entity.Tuple) HashSet(java.util.HashSet)

Example 2 with TupleBuilder

use of org.bboxdb.tools.converter.tuple.TupleBuilder 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 3 with TupleBuilder

use of org.bboxdb.tools.converter.tuple.TupleBuilder 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 4 with TupleBuilder

use of org.bboxdb.tools.converter.tuple.TupleBuilder 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 5 with TupleBuilder

use of org.bboxdb.tools.converter.tuple.TupleBuilder 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)

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