Skip to content

Commit ff3b4d9

Browse files
Added the Schema Evolution API
1 parent 1185fc9 commit ff3b4d9

File tree

13 files changed

+881
-22
lines changed

13 files changed

+881
-22
lines changed

src/main/c/generated/tiledb_wrap.cxx

Lines changed: 356 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/io/tiledb/java/api/Array.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,25 @@ public static void consolidate(
392392
}
393393
}
394394

395+
/**
396+
* Evolves the schema of an array.
397+
*
398+
* <p>**Example:** ArraySchemaEvolution schemaEvolution = new ArraySchemaEvolution(ctx);
399+
* schemaEvolution.dropAttribute("attName"); array.evolve(ctx, schemaEvolution);
400+
*
401+
* @param ctx A TileDb context
402+
* @param schemaEvolution The schemaEvolution object
403+
* @throws TileDBError
404+
*/
405+
public void evolve(Context ctx, ArraySchemaEvolution schemaEvolution) throws TileDBError {
406+
try {
407+
ctx.handleError(
408+
tiledb.tiledb_array_evolve(ctx.getCtxp(), uri, schemaEvolution.getEvolutionp()));
409+
} catch (TileDBError err) {
410+
throw err;
411+
}
412+
}
413+
395414
/**
396415
* Cleans up the array, such as consolidated fragments and array metadata. Note that this will
397416
* coarsen the granularity of time traveling (see docs for more information).
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package io.tiledb.java.api;
2+
3+
import io.tiledb.libtiledb.SWIGTYPE_p_p_tiledb_array_schema_evolution_t;
4+
import io.tiledb.libtiledb.SWIGTYPE_p_tiledb_array_schema_evolution_t;
5+
import io.tiledb.libtiledb.tiledb;
6+
7+
public class ArraySchemaEvolution implements AutoCloseable {
8+
private Context ctx;
9+
private SWIGTYPE_p_tiledb_array_schema_evolution_t evolutionp;
10+
private SWIGTYPE_p_p_tiledb_array_schema_evolution_t evolutionpp;
11+
12+
public ArraySchemaEvolution(
13+
Context ctx, SWIGTYPE_p_p_tiledb_array_schema_evolution_t evolutionpp) {
14+
this.ctx = ctx;
15+
this.evolutionp = tiledb.tiledb_array_schema_evolution_tpp_value(evolutionpp);
16+
this.evolutionpp = evolutionpp;
17+
}
18+
19+
public ArraySchemaEvolution(Context ctx) throws TileDBError {
20+
evolutionpp = tiledb.new_tiledb_array_schema_evolution_tpp();
21+
try {
22+
ctx.handleError(tiledb.tiledb_array_schema_evolution_alloc(ctx.getCtxp(), evolutionpp));
23+
} catch (TileDBError err) {
24+
tiledb.delete_tiledb_array_schema_evolution_tpp(evolutionpp);
25+
throw err;
26+
}
27+
28+
evolutionp = tiledb.tiledb_array_schema_evolution_tpp_value(evolutionpp);
29+
this.ctx = ctx;
30+
}
31+
32+
public SWIGTYPE_p_tiledb_array_schema_evolution_t getEvolutionp() {
33+
return this.evolutionp;
34+
}
35+
36+
protected Context getCtx() {
37+
return this.ctx;
38+
}
39+
40+
public void close() {
41+
if (evolutionp != null && evolutionpp != null) {
42+
tiledb.tiledb_array_schema_evolution_free(evolutionpp);
43+
evolutionpp = null;
44+
evolutionp = null;
45+
}
46+
}
47+
48+
/**
49+
* Adds an Attribute to the array schema evolution.
50+
*
51+
* <p>**Example:** ArraySchemaEvolution schemaEvolution = new ArraySchemaEvolution(ctx);
52+
* schemaEvolution.addAttribute(new Attribute(ctx, "newAtt", Float.class));
53+
*
54+
* @param att The Attribute to add
55+
* @throws TileDBError
56+
*/
57+
public void addAttribute(Attribute att) throws TileDBError {
58+
try {
59+
ctx.handleError(tiledb.tiledb_array_schema_evolution_alloc(ctx.getCtxp(), evolutionpp));
60+
ctx.handleError(
61+
tiledb.tiledb_array_schema_evolution_add_attribute(
62+
ctx.getCtxp(), evolutionp, att.getAttributep()));
63+
} catch (TileDBError err) {
64+
tiledb.delete_tiledb_array_schema_evolution_tpp(evolutionpp);
65+
throw err;
66+
}
67+
}
68+
69+
/**
70+
* Drops an Attribute from the array schema evolution.
71+
*
72+
* <p>**Example:** ArraySchemaEvolution schemaEvolution = new ArraySchemaEvolution(ctx);
73+
* schemaEvolution.dropAttribute("attName");
74+
*
75+
* @param attName The name of the Attribute to drop
76+
* @throws TileDBError
77+
*/
78+
public void dropAttribute(String attName) throws TileDBError {
79+
try {
80+
ctx.handleError(tiledb.tiledb_array_schema_evolution_alloc(ctx.getCtxp(), evolutionpp));
81+
ctx.handleError(
82+
tiledb.tiledb_array_schema_evolution_drop_attribute(ctx.getCtxp(), evolutionp, attName));
83+
} catch (TileDBError err) {
84+
tiledb.delete_tiledb_array_schema_evolution_tpp(evolutionpp);
85+
throw err;
86+
}
87+
}
88+
89+
/**
90+
* Drops an Attribute from the array schema evolution.
91+
*
92+
* <p>**Example:** ArraySchemaEvolution schemaEvolution = new ArraySchemaEvolution(ctx);
93+
* schemaEvolution.dropAttribute("attName");
94+
*
95+
* @param att The Attribute to drop
96+
* @throws TileDBError
97+
*/
98+
public void dropAttribute(Attribute att) throws TileDBError {
99+
try {
100+
ctx.handleError(tiledb.tiledb_array_schema_evolution_alloc(ctx.getCtxp(), evolutionpp));
101+
ctx.handleError(
102+
tiledb.tiledb_array_schema_evolution_drop_attribute(
103+
ctx.getCtxp(), evolutionp, att.getName()));
104+
} catch (TileDBError err) {
105+
tiledb.delete_tiledb_array_schema_evolution_tpp(evolutionpp);
106+
throw err;
107+
}
108+
}
109+
110+
/**
111+
* Evolves the schema of an array.
112+
*
113+
* <p>**Example:** ArraySchemaEvolution schemaEvolution = new ArraySchemaEvolution(ctx);
114+
* schemaEvolution.dropAttribute("attName"); schemaEvolution.evolveArray("testUri")
115+
*
116+
* @param uri
117+
* @throws TileDBError
118+
*/
119+
public void evolveArray(String uri) throws TileDBError {
120+
try {
121+
ctx.handleError(tiledb.tiledb_array_schema_evolution_alloc(ctx.getCtxp(), evolutionpp));
122+
ctx.handleError(tiledb.tiledb_array_evolve(ctx.getCtxp(), uri, evolutionp));
123+
} catch (TileDBError err) {
124+
tiledb.delete_tiledb_array_schema_evolution_tpp(evolutionpp);
125+
throw err;
126+
}
127+
}
128+
}

src/main/java/io/tiledb/libtiledb/NativeLibLoader.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@
3535
import java.util.Locale;
3636
import java.util.Properties;
3737
import java.util.Set;
38+
import java.util.logging.Logger;
3839
import java.util.stream.Stream;
3940

4041
/** Helper class that finds native libraries embedded as resources and loads them dynamically. */
4142
public class NativeLibLoader {
4243

44+
private static final Logger LOGGER = Logger.getLogger(NativeLibLoader.class.getName());
45+
4346
private static final String UNKNOWN = "unknown";
4447

4548
/** Path (relative to jar) where native libraries are located. */
@@ -71,24 +74,25 @@ static void loadNativeTileDB() {
7174
try {
7275
loadNativeLib("tiledb", true);
7376
} catch (java.lang.UnsatisfiedLinkError e) {
77+
LOGGER.warning("Could not load Native TIleDB");
7478
// If a native library fails to link, we fall back to depending on the system
7579
// dynamic linker to satisfy the requirement. Therefore, we do nothing here
7680
// (if the library is not available via the system linker, a runtime error
7781
// will occur later).
7882
}
7983
}
8084

81-
/** Finds and loads native Intel Thread Building Blocks. */
82-
static void loadNativeTBB() {
83-
try {
84-
loadNativeLib("tbb", true);
85-
} catch (java.lang.UnsatisfiedLinkError e) {
86-
// If a native library fails to link, we fall back to depending on the system
87-
// dynamic linker to satisfy the requirement. Therefore, we do nothing here
88-
// (if the library is not available via the system linker, a runtime error
89-
// will occur later).
90-
}
91-
}
85+
// /** Finds and loads native Intel Thread Building Blocks. */
86+
// static void loadNativeTBB() {
87+
// try {
88+
// loadNativeLib("tbb", true);
89+
// } catch (java.lang.UnsatisfiedLinkError e) {
90+
// // If a native library fails to link, we fall back to depending on the system
91+
// // dynamic linker to satisfy the requirement. Therefore, we do nothing here
92+
// // (if the library is not available via the system linker, a runtime error
93+
// // will occur later).
94+
// }
95+
// }
9296

9397
/** Finds and loads native TileDB JNI. */
9498
static void loadNativeTileDBJNI() {
@@ -317,7 +321,7 @@ private static Path extractLibraryFile(
317321
*/
318322
private static Path findNativeLibrary(String libraryName, boolean mapLibraryName) {
319323
String mappedLibraryName = mapLibraryName ? System.mapLibraryName(libraryName) : libraryName;
320-
String libDir = LIB_RESOURCE_DIR;
324+
String libDir = LIB_RESOURCE_DIR + "/" + getOSClassifier();
321325
String libPath = libDir + "/" + mappedLibraryName;
322326

323327
boolean hasNativeLib = hasResource(libPath);

src/main/java/io/tiledb/libtiledb/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* ----------------------------------------------------------------------------
2+
* This file was automatically generated by SWIG (http://www.swig.org).
3+
* Version 4.0.2
4+
*
5+
* Do not make changes to this file unless you know what you are doing--modify
6+
* the SWIG interface file instead.
7+
* ----------------------------------------------------------------------------- */
8+
9+
package io.tiledb.libtiledb;
10+
11+
public class SWIGTYPE_p_p_tiledb_array_schema_evolution_t {
12+
private transient long swigCPtr;
13+
14+
protected SWIGTYPE_p_p_tiledb_array_schema_evolution_t(
15+
long cPtr, @SuppressWarnings("unused") boolean futureUse) {
16+
swigCPtr = cPtr;
17+
}
18+
19+
protected SWIGTYPE_p_p_tiledb_array_schema_evolution_t() {
20+
swigCPtr = 0;
21+
}
22+
23+
protected static long getCPtr(SWIGTYPE_p_p_tiledb_array_schema_evolution_t obj) {
24+
return (obj == null) ? 0 : obj.swigCPtr;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* ----------------------------------------------------------------------------
2+
* This file was automatically generated by SWIG (http://www.swig.org).
3+
* Version 4.0.2
4+
*
5+
* Do not make changes to this file unless you know what you are doing--modify
6+
* the SWIG interface file instead.
7+
* ----------------------------------------------------------------------------- */
8+
9+
package io.tiledb.libtiledb;
10+
11+
public class SWIGTYPE_p_tiledb_array_schema_evolution_t {
12+
private transient long swigCPtr;
13+
14+
protected SWIGTYPE_p_tiledb_array_schema_evolution_t(
15+
long cPtr, @SuppressWarnings("unused") boolean futureUse) {
16+
swigCPtr = cPtr;
17+
}
18+
19+
protected SWIGTYPE_p_tiledb_array_schema_evolution_t() {
20+
swigCPtr = 0;
21+
}
22+
23+
protected static long getCPtr(SWIGTYPE_p_tiledb_array_schema_evolution_t obj) {
24+
return (obj == null) ? 0 : obj.swigCPtr;
25+
}
26+
}

0 commit comments

Comments
 (0)