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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations