use of io.tiledb.java.api.Layout in project TileDB-Spark by TileDB-Inc.
the class TileDBDataSourceOptionsTest method testInvalidLayoutOptions.
@Test(expected = IllegalArgumentException.class)
public void testInvalidLayoutOptions() throws Exception {
HashMap<String, String> optionMap = new HashMap<>();
optionMap.put("order", "bad-layout-option");
TileDBDataSourceOptions options = new TileDBDataSourceOptions(new DataSourceOptions(optionMap));
Optional<Layout> layout = options.getArrayLayout();
}
use of io.tiledb.java.api.Layout in project TileDB-Spark by TileDB-Inc.
the class TileDBBatchWrite method writeArraySchema.
private static void writeArraySchema(Context ctx, URI uri, StructType sparkSchema, TileDBDataSourceOptions options) throws TileDBError {
ArrayType type = ArrayType.TILEDB_SPARSE;
try (ArraySchema arraySchema = new ArraySchema(ctx, type);
Domain domain = new Domain(ctx)) {
String[] dimNames = TileDBWriteSchema.getSchemaDimensionOptions(sparkSchema, options);
StructField[] sparkFields = sparkSchema.fields();
for (int dimIdx = 0; dimIdx < dimNames.length; dimIdx++) {
String dimName = dimNames[dimIdx];
int idx = sparkSchema.fieldIndex(dimName);
try (Dimension dim = TileDBWriteSchema.toDimension(ctx, dimName, dimIdx, sparkFields[idx].dataType(), options)) {
domain.addDimension(dim);
}
}
// set domain
arraySchema.setDomain(domain);
// add attributes
for (StructField field : sparkFields) {
// skip over dims
if (Arrays.stream(dimNames).anyMatch(field.name()::equals)) {
continue;
}
try (Attribute attr = TileDBWriteSchema.toAttribute(ctx, field, options)) {
arraySchema.addAttribute(attr);
}
}
// set schema tile / layouts and remaining attributes
Optional<Layout> schemaCellOrder = options.getSchemaCellOrder();
if (schemaCellOrder.isPresent()) {
arraySchema.setCellOrder(schemaCellOrder.get());
}
Optional<Layout> schemaTileOrder = options.getSchemaTileOrder();
if (schemaTileOrder.isPresent()) {
arraySchema.setTileOrder(schemaTileOrder.get());
}
// schema filters
Optional<List<Pair<String, Integer>>> coordsFilters = options.getSchemaCoordsFilterList();
if (coordsFilters.isPresent()) {
try (FilterList filterList = TileDBWriteSchema.createTileDBFilterList(ctx, coordsFilters.get())) {
arraySchema.setCoodsFilterList(filterList);
}
}
Optional<List<Pair<String, Integer>>> offsetsFilters = options.getSchemaOffsetsFilterList();
if (coordsFilters.isPresent()) {
try (FilterList filterList = TileDBWriteSchema.createTileDBFilterList(ctx, offsetsFilters.get())) {
arraySchema.setOffsetsFilterList(filterList);
}
}
// set capacity
Optional<Long> schemaCapacity = options.getSchemaCapacity();
if (schemaCapacity.isPresent()) {
arraySchema.setCapacity(schemaCapacity.get());
}
// set allows dups
if (options.getSchemaAllowDups().isPresent() && options.getSchemaAllowDups().get())
arraySchema.setAllowDups(1);
arraySchema.check();
Array.create(uri.toString(), arraySchema);
}
}
use of io.tiledb.java.api.Layout in project TileDB-Spark by TileDB-Inc.
the class TileDBDataSourceOptionsTest method testValidArrayLayoutOptions.
@Test
public void testValidArrayLayoutOptions() throws Exception {
String[] validLayoutStrings = new String[] { "row-major", "TILEDB_ROW_MAJOR", "col-major", "TILEDB_COL_MAJOR", "unordered", "TILEDB_UNORDERED" };
Layout[] expectedLayouts = new Layout[] { Layout.TILEDB_ROW_MAJOR, Layout.TILEDB_ROW_MAJOR, Layout.TILEDB_COL_MAJOR, Layout.TILEDB_COL_MAJOR, Layout.TILEDB_UNORDERED, Layout.TILEDB_UNORDERED };
for (int i = 0; i < validLayoutStrings.length; i++) {
HashMap<String, String> optionMap = new HashMap<>();
optionMap.put("order", validLayoutStrings[i]);
TileDBDataSourceOptions options = new TileDBDataSourceOptions(new DataSourceOptions(optionMap));
Optional<Layout> layout = options.getArrayLayout();
Assert.assertTrue(layout.isPresent());
Assert.assertEquals(expectedLayouts[i], layout.get());
}
}
Aggregations