tableProperties)
109 | {
110 | return (String) tableProperties.get(EncryptionKey);
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/io/trino/plugin/tiledb/TileDBTransactionHandle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package io.trino.plugin.tiledb;
15 |
16 | import com.fasterxml.jackson.annotation.JsonCreator;
17 | import com.fasterxml.jackson.annotation.JsonProperty;
18 | import io.trino.spi.connector.ConnectorTransactionHandle;
19 |
20 | import java.util.Objects;
21 | import java.util.UUID;
22 |
23 | import static com.google.common.base.MoreObjects.toStringHelper;
24 | import static java.util.Objects.requireNonNull;
25 |
26 | /**
27 | * TileDBTransactionHandle is a simple transaction handler by declaring a single enum type for a transaction.
28 | * Since tiledb has no transactions we use "instance level" transactions, which I believe just means a transaction
29 | * in presto is mapped to a connector instance's lifespan.
30 | */
31 | public class TileDBTransactionHandle
32 | implements ConnectorTransactionHandle
33 | {
34 | private final UUID uuid;
35 |
36 | public TileDBTransactionHandle()
37 | {
38 | this(UUID.randomUUID());
39 | }
40 |
41 | @JsonCreator
42 | public TileDBTransactionHandle(@JsonProperty("uuid") UUID uuid)
43 | {
44 | this.uuid = requireNonNull(uuid, "uuid is null");
45 | }
46 |
47 | @JsonProperty
48 | public UUID getUuid()
49 | {
50 | return uuid;
51 | }
52 |
53 | @Override
54 | public boolean equals(Object obj)
55 | {
56 | if (this == obj) {
57 | return true;
58 | }
59 | if ((obj == null) || (getClass() != obj.getClass())) {
60 | return false;
61 | }
62 | TileDBTransactionHandle other = (TileDBTransactionHandle) obj;
63 | return Objects.equals(uuid, other.uuid);
64 | }
65 |
66 | @Override
67 | public int hashCode()
68 | {
69 | return Objects.hash(uuid);
70 | }
71 |
72 | @Override
73 | public String toString()
74 | {
75 | return toStringHelper(this)
76 | .add("uuid", uuid)
77 | .toString();
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/io/trino/plugin/tiledb/util/StringPartitioner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package io.trino.plugin.tiledb.util;
16 |
17 | import io.tiledb.java.api.Pair;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | public class StringPartitioner
23 | {
24 | private int minChar;
25 | private int maxChar;
26 |
27 | public StringPartitioner()
28 | {
29 | minChar = 0;
30 | maxChar = 127;
31 | }
32 |
33 | public StringPartitioner(int minChar, int maxChar)
34 | {
35 | this.minChar = minChar;
36 | this.maxChar = maxChar;
37 | }
38 |
39 | /**
40 | * Computes the next possible string by incrementing the least possible character. The next string
41 | * is limited to the input string length. For example, if the maximum character provided is 'z',
42 | * then a string like `zzz` cannot be further incremented and it will be returned as it is. On the
43 | * other hand, the next string of `aaz` will be `aba`, the next of `a` `b` and so on.
44 | *
45 | * The example above is assumes the a-z alphabet for simplicity. In practice, the next string
46 | * depends on the min/max chars defined by the user in the StringPartitioner constructor. The
47 | * default values are the min and max ASCII characters.
48 | *
49 | * @param str The input string
50 | * @return The next string
51 | */
52 | public String nextStr(String str)
53 | {
54 | int strLen = str.length();
55 |
56 | char[] charArray = str.toCharArray();
57 |
58 | int currentCharIdx = strLen - 1;
59 |
60 | while (currentCharIdx > 0 && charArray[currentCharIdx] == maxChar) {
61 | charArray[currentCharIdx] = (char) minChar;
62 | --currentCharIdx;
63 | }
64 |
65 | if (charArray[currentCharIdx] < maxChar) {
66 | charArray[currentCharIdx]++;
67 | }
68 |
69 | return new String(charArray);
70 | }
71 |
72 | /**
73 | * Computes a the n-th next string
74 | *
75 | * @param str The input string
76 | * @param n The n value
77 | * @return The n-th next string
78 | */
79 | public String nextStr(String str, long n)
80 | {
81 | for (int i = 0; i < n; ++i) {
82 | str = this.nextStr(str);
83 | }
84 |
85 | return str;
86 | }
87 |
88 | /**
89 | * Computes the previous possible string by reducing the least possible character by one.
90 | * For example, if the minimum character provided is 'a', then a string like `aaa` cannot be further reduced
91 | * and it will be returned as it is. On the other hand, the next previous of `abc` will be `abb`,
92 | * the previous of `b` will be `a` and so on.
93 | *
94 | *
The example above is assumes the a-z alphabet for simplicity. In practice, the next string
95 | * depends on the min/max chars defined by the user in the StringPartitioner constructor. The
96 | * default values are the min and max ASCII characters.
97 | *
98 | * @param str The input string
99 | * @return The next string
100 | */
101 | public String previousStr(String str)
102 | {
103 | int strLen = str.length();
104 |
105 | char[] charArray = str.toCharArray();
106 |
107 | int currentCharIdx = strLen - 1;
108 |
109 | while (currentCharIdx > 0 && charArray[currentCharIdx] == minChar) {
110 | charArray[currentCharIdx] = (char) minChar;
111 | --currentCharIdx;
112 | }
113 |
114 | if (charArray[currentCharIdx] > minChar) {
115 | charArray[currentCharIdx]--;
116 | }
117 |
118 | return new String(charArray);
119 | }
120 |
121 | /**
122 | * Returns the distance between two strings. By distance, we mean the maximum possible strings
123 | * that can be created between a1 and a2 in lexicographical order.
124 | *
125 | * @param a1 The left bound
126 | * @param a2 The right bound
127 | * @return The number of possible strings
128 | */
129 | public int distance(String a1, String a2)
130 | {
131 | String tmp = a1;
132 | int dist = 0;
133 | while (tmp.compareTo(a2) < 0) {
134 | tmp = this.nextStr(tmp);
135 | ++dist;
136 | }
137 |
138 | return dist;
139 | }
140 |
141 | /**
142 | * Adds extra chars to the input string
143 | *
144 | * @param str The input string
145 | * @param c The char to be added to the end of the string
146 | * @param n The occurrences of c to be added
147 | * @return The new string
148 | */
149 | public static String addExtraChars(String str, char c, int n)
150 | {
151 | char[] newStr = new char[str.length() + n];
152 | int idx = 0;
153 |
154 | for (char character : str.toCharArray()) {
155 | newStr[idx++] = character;
156 | }
157 |
158 | while (idx < str.length() + n) {
159 | newStr[idx++] = c;
160 | }
161 |
162 | return new String(newStr);
163 | }
164 |
165 | /**
166 | * Splits a String range into equi-width sub-ranges
167 | *
168 | * @param start The left bound
169 | * @param end The right bound
170 | * @param partitions The number of partitions
171 | * @return A list of pairs with the sub-range bounds
172 | */
173 | public List> split(String start, String end, int partitions)
174 | {
175 | String fixedStart = start;
176 | long width = this.distance(fixedStart, end);
177 |
178 | while (width / partitions < 1) {
179 | // In this case we need to add extra characters to the left string
180 | fixedStart = addExtraChars(fixedStart, (char) minChar, 1);
181 | width = this.distance(fixedStart, end);
182 | }
183 |
184 | long partitionWidth = (width / partitions);
185 |
186 | String tmpStart = fixedStart;
187 | String tmpEnd;
188 |
189 | List> list = new ArrayList<>();
190 |
191 | for (int i = 0; i < partitions; ++i) {
192 | if (i == partitions - 1) {
193 | tmpEnd = end;
194 | }
195 | else {
196 | tmpEnd = nextStr(tmpStart, partitionWidth);
197 | }
198 |
199 | if (i == 0) {
200 | tmpStart = start;
201 | }
202 |
203 | if (tmpEnd.compareTo(end) > 0) {
204 | tmpEnd = end;
205 | list.add(new Pair(new String(tmpStart.toCharArray()), new String(tmpEnd.toCharArray())));
206 | break;
207 | }
208 |
209 | list.add(new Pair(new String(tmpStart.toCharArray()), new String(tmpEnd.toCharArray())));
210 | tmpStart = nextStr(tmpEnd, 1);
211 | }
212 |
213 | return list;
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/src/main/java/io/trino/plugin/tiledb/util/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package io.trino.plugin.tiledb.util;
15 |
16 | import io.tiledb.java.api.BitShuffleFilter;
17 | import io.tiledb.java.api.BitWidthReductionFilter;
18 | import io.tiledb.java.api.ByteShuffleFilter;
19 | import io.tiledb.java.api.Bzip2Filter;
20 | import io.tiledb.java.api.Context;
21 | import io.tiledb.java.api.Datatype;
22 | import io.tiledb.java.api.Dimension;
23 | import io.tiledb.java.api.Domain;
24 | import io.tiledb.java.api.DoubleDeltaFilter;
25 | import io.tiledb.java.api.Filter;
26 | import io.tiledb.java.api.FilterList;
27 | import io.tiledb.java.api.GzipFilter;
28 | import io.tiledb.java.api.LZ4Filter;
29 | import io.tiledb.java.api.NoneFilter;
30 | import io.tiledb.java.api.Pair;
31 | import io.tiledb.java.api.TileDBError;
32 | import io.tiledb.java.api.ZstdFilter;
33 |
34 | import java.util.ArrayList;
35 | import java.util.Arrays;
36 | import java.util.List;
37 | import java.util.Optional;
38 | import java.util.regex.Matcher;
39 | import java.util.regex.Pattern;
40 |
41 | public class Util
42 | {
43 | private Util() {}
44 |
45 | /**
46 | * The String Partitioner
47 | */
48 | private static final StringPartitioner stringPartitioner = new StringPartitioner();
49 |
50 | public static Dimension toDimension(Context localCtx, String dimName, Datatype type, Domain domain, Long extent,
51 | Long lowerBound, Long upperBound)
52 | throws TileDBError
53 | {
54 | Class classType = type.javaClass();
55 | switch (type) {
56 | case TILEDB_INT8:
57 | if (extent > Byte.MAX_VALUE) {
58 | extent = 10000L;
59 | }
60 | if (upperBound > Byte.MAX_VALUE - extent) {
61 | upperBound = (long) Byte.MAX_VALUE - extent;
62 | }
63 | else if (upperBound < Byte.MIN_VALUE) {
64 | upperBound = (long) Byte.MIN_VALUE + extent;
65 | }
66 | if (lowerBound > Byte.MAX_VALUE) {
67 | lowerBound = (long) Byte.MAX_VALUE - extent;
68 | }
69 | else if (lowerBound < Byte.MIN_VALUE) {
70 | lowerBound = (long) Byte.MIN_VALUE;
71 | }
72 | return new Dimension(localCtx, dimName, classType, new Pair(lowerBound.byteValue(), upperBound.byteValue()), extent.byteValue());
73 | case TILEDB_INT16:
74 | if (extent > Short.MAX_VALUE) {
75 | extent = 10000L;
76 | }
77 | if (upperBound > Short.MAX_VALUE - extent) {
78 | upperBound = (long) Short.MAX_VALUE - extent;
79 | }
80 | else if (upperBound < Short.MIN_VALUE) {
81 | upperBound = (long) Short.MIN_VALUE + extent;
82 | }
83 | if (lowerBound > Short.MAX_VALUE) {
84 | lowerBound = (long) Short.MAX_VALUE - extent;
85 | }
86 | else if (lowerBound < Short.MIN_VALUE) {
87 | lowerBound = (long) Short.MIN_VALUE;
88 | }
89 | return new Dimension(localCtx, dimName, classType, new Pair(lowerBound.shortValue(), upperBound.shortValue()), extent.shortValue());
90 | case TILEDB_INT32:
91 | if (extent > Integer.MAX_VALUE) {
92 | extent = 10000L;
93 | }
94 | if (upperBound > Integer.MAX_VALUE - extent) {
95 | upperBound = (long) Integer.MAX_VALUE - extent;
96 | }
97 | else if (upperBound < Integer.MIN_VALUE) {
98 | upperBound = (long) Integer.MIN_VALUE + extent;
99 | }
100 | if (lowerBound > Integer.MAX_VALUE) {
101 | lowerBound = (long) Integer.MAX_VALUE - extent;
102 | }
103 | else if (lowerBound < Integer.MIN_VALUE) {
104 | lowerBound = (long) Integer.MIN_VALUE;
105 | }
106 | return new Dimension(localCtx, dimName, classType, new Pair(lowerBound.intValue(), upperBound.intValue()), extent.intValue());
107 | case TILEDB_DATETIME_AS:
108 | case TILEDB_DATETIME_FS:
109 | case TILEDB_DATETIME_PS:
110 | case TILEDB_DATETIME_NS:
111 | case TILEDB_DATETIME_US:
112 | case TILEDB_DATETIME_MS:
113 | case TILEDB_DATETIME_SEC:
114 | case TILEDB_DATETIME_MIN:
115 | case TILEDB_DATETIME_HR:
116 | case TILEDB_DATETIME_DAY:
117 | case TILEDB_DATETIME_WEEK:
118 | case TILEDB_DATETIME_MONTH:
119 | case TILEDB_DATETIME_YEAR:
120 | case TILEDB_INT64:
121 | if (upperBound > Long.MAX_VALUE - extent) {
122 | upperBound = (long) Long.MAX_VALUE - extent;
123 | }
124 | return new Dimension(localCtx, dimName, type, new Pair(lowerBound, upperBound), extent);
125 | case TILEDB_FLOAT32:
126 | if (upperBound > Float.MAX_VALUE - extent) {
127 | upperBound = (long) Float.MAX_VALUE - extent;
128 | }
129 | else if (upperBound < Float.MIN_VALUE) {
130 | upperBound = (long) Float.MIN_VALUE + extent;
131 | }
132 | if (lowerBound > Float.MAX_VALUE) {
133 | lowerBound = (long) Float.MAX_VALUE - extent;
134 | }
135 | else if (lowerBound < Float.MIN_VALUE) {
136 | lowerBound = (long) Float.MIN_VALUE;
137 | }
138 | if (extent > Float.MAX_VALUE) {
139 | extent = (long) Float.MAX_VALUE;
140 | }
141 | return new Dimension(localCtx, dimName, classType, new Pair(lowerBound.floatValue(), upperBound.floatValue()), extent.floatValue());
142 | case TILEDB_FLOAT64:
143 | if (upperBound > Double.MAX_VALUE - extent) {
144 | upperBound = (long) Double.MAX_VALUE - extent;
145 | }
146 | else if (upperBound < Double.MIN_VALUE) {
147 | upperBound = (long) Double.MIN_VALUE + extent;
148 | }
149 | if (lowerBound > Double.MAX_VALUE) {
150 | lowerBound = (long) Double.MAX_VALUE - extent;
151 | }
152 | else if (lowerBound < Double.MIN_VALUE) {
153 | lowerBound = (long) Double.MIN_VALUE;
154 | }
155 | if (extent > Double.MAX_VALUE) {
156 | extent = (long) Double.MAX_VALUE;
157 | }
158 | return new Dimension(localCtx, dimName, classType, new Pair(lowerBound.doubleValue(), upperBound.doubleValue()), extent.doubleValue());
159 | case TILEDB_STRING_ASCII:
160 | return new Dimension(localCtx, dimName, type, null, null);
161 | default:
162 | throw new TileDBError(String.format("Invalid dimension datatype %s, must be one of [TINYINT, SMALLINT, INTEGER, BIGINT, REAL, DOUBLE]", type.toString()));
163 | }
164 | }
165 |
166 | /**
167 | * Parses a comma-separated filter list and returns a list with key-value pairs,
168 | * where the key is the filter name (e.g. bzip2) and the value the filter's value
169 | * (e.g. -1)
170 | *
171 | * @param csvList The csv list
172 | * @return the parsed filter list
173 | * @throws IllegalArgumentException Exception
174 | */
175 | public static Optional>> tryParseFilterList(String csvList)
176 | throws IllegalArgumentException
177 | {
178 | // filter lists are in the form "(filter, option), (filter, option), etc.")
179 | List> filterResults = new ArrayList<>();
180 | // String[] splitVals = csvList.split("\\s*,\\s*");
181 | Pattern filterListRegex = Pattern.compile("\\((.*?)\\)");
182 | Matcher filterListMatcher = filterListRegex.matcher(csvList);
183 | while (filterListMatcher.find()) {
184 | String filterString = filterListMatcher.group(1);
185 | String[] filterPair = filterString.split("\\s*,\\s*");
186 | // remove parens
187 | String filterName = filterPair[0];
188 | List validFilters = Arrays.asList(new String[]{"GZIP", "ZSTD", "LZ4", "RLE", "BZIP2",
189 | "DOUBLE_DELTA", "BIT_WIDTH_REDUCTION", "BITSHUFFLE", "BYTESHUFFLE", "POSITIVE_DELTA"});
190 |
191 | if (!validFilters.contains(filterName.toUpperCase())) {
192 | throw new IllegalArgumentException("Unknown TileDB filter string value: " + filterName);
193 | }
194 | Integer filterOption = -1;
195 | if (filterPair.length == 2) {
196 | // remove parens
197 | String filterOptionStr = filterPair[1];
198 | try {
199 | filterOption = Integer.parseInt(filterOptionStr);
200 | }
201 | catch (NumberFormatException err) {
202 | throw new IllegalArgumentException(
203 | "Cannot parse filter option value for " + filterName + ": " + filterOptionStr);
204 | }
205 | }
206 | filterResults.add(new Pair<>(filterName, filterOption));
207 | }
208 | if (filterResults.isEmpty()) {
209 | return Optional.empty();
210 | }
211 | return Optional.of(filterResults);
212 | }
213 |
214 | /**
215 | * Returns a TileDB FilterList
216 | *
217 | * @param ctx The context
218 | * @param filterListDesc The filter pairs list extracted with the tryParseFilterList method
219 | * @return The FilterList instance
220 | * @throws TileDBError TileDBError
221 | */
222 | public static FilterList createTileDBFilterList(
223 | Context ctx, List> filterListDesc)
224 | throws TileDBError
225 | {
226 | FilterList filterList = new FilterList(ctx);
227 | try {
228 | for (Pair filterDesc : filterListDesc) {
229 | String filterName = filterDesc.getFirst();
230 | Integer filterOption = filterDesc.getSecond();
231 | if (filterName.equalsIgnoreCase("NONE")) {
232 | try (Filter filter = new NoneFilter(ctx)) {
233 | filterList.addFilter(filter);
234 | }
235 | }
236 | else if (filterName.equalsIgnoreCase("GZIP")) {
237 | try (Filter filter = new GzipFilter(ctx, filterOption)) {
238 | filterList.addFilter(filter);
239 | }
240 | }
241 | else if (filterName.equalsIgnoreCase("ZSTD")) {
242 | try (Filter filter = new ZstdFilter(ctx, filterOption)) {
243 | filterList.addFilter(filter);
244 | }
245 | }
246 | else if (filterName.equalsIgnoreCase("LZ4")) {
247 | try (Filter filter = new LZ4Filter(ctx, filterOption)) {
248 | filterList.addFilter(filter);
249 | }
250 | }
251 | else if (filterName.equalsIgnoreCase("RLE")) {
252 | try (Filter filter = new LZ4Filter(ctx, filterOption)) {
253 | filterList.addFilter(filter);
254 | }
255 | }
256 | else if (filterName.equalsIgnoreCase("BZIP2")) {
257 | try (Filter filter = new Bzip2Filter(ctx, filterOption)) {
258 | filterList.addFilter(filter);
259 | }
260 | }
261 | else if (filterName.equalsIgnoreCase("DOUBLE_DELTA")) {
262 | try (Filter filter = new DoubleDeltaFilter(ctx, filterOption)) {
263 | filterList.addFilter(filter);
264 | }
265 | }
266 | else if (filterName.equalsIgnoreCase("BIT_WIDTH_REDUCTION")) {
267 | try (Filter filter = new BitWidthReductionFilter(ctx, filterOption)) {
268 | filterList.addFilter(filter);
269 | }
270 | }
271 | else if (filterName.equalsIgnoreCase("BITSHUFFLE")) {
272 | try (Filter filter = new BitShuffleFilter(ctx)) {
273 | filterList.addFilter(filter);
274 | }
275 | }
276 | else if (filterName.equalsIgnoreCase("BYTESHUFFLE")) {
277 | try (Filter filter = new ByteShuffleFilter(ctx)) {
278 | filterList.addFilter(filter);
279 | }
280 | }
281 | else if (filterName.equalsIgnoreCase("POSITIVE_DELTA")) {
282 | try (Filter filter = new ByteShuffleFilter(ctx)) {
283 | filterList.addFilter(filter);
284 | }
285 | }
286 | }
287 | }
288 | catch (TileDBError err) {
289 | filterList.close();
290 | throw err;
291 | }
292 | return filterList;
293 | }
294 |
295 | /**
296 | * Returns v + eps, where eps is the smallest value for the datatype such that v + eps > v.
297 | */
298 | public static Object addEpsilon(Object value, Datatype type)
299 | throws TileDBError
300 | {
301 | switch (type) {
302 | case TILEDB_CHAR:
303 | case TILEDB_INT8:
304 | return ((byte) value) < Byte.MAX_VALUE ? ((byte) value + 1) : value;
305 | case TILEDB_INT16:
306 | return ((short) value) < Short.MAX_VALUE ? ((short) value + 1) : value;
307 | case TILEDB_INT32:
308 | return ((int) value) < Integer.MAX_VALUE ? ((int) value + 1) : value;
309 | case TILEDB_DATETIME_AS:
310 | case TILEDB_DATETIME_FS:
311 | case TILEDB_DATETIME_PS:
312 | case TILEDB_DATETIME_NS:
313 | case TILEDB_DATETIME_US:
314 | case TILEDB_DATETIME_MS:
315 | case TILEDB_DATETIME_SEC:
316 | case TILEDB_DATETIME_MIN:
317 | case TILEDB_DATETIME_HR:
318 | case TILEDB_DATETIME_DAY:
319 | case TILEDB_DATETIME_WEEK:
320 | case TILEDB_DATETIME_MONTH:
321 | case TILEDB_DATETIME_YEAR:
322 | case TILEDB_INT64:
323 | return ((long) value) < Long.MAX_VALUE ? ((long) value + 1) : value;
324 | case TILEDB_UINT8:
325 | return ((short) value) < ((short) Byte.MAX_VALUE + 1) ? ((short) value + 1) : value;
326 | case TILEDB_UINT16:
327 | return ((int) value) < ((int) Short.MAX_VALUE + 1) ? ((int) value + 1) : value;
328 | case TILEDB_UINT32:
329 | return ((long) value) < ((long) Integer.MAX_VALUE + 1) ? ((long) value + 1) : value;
330 | case TILEDB_UINT64:
331 | return ((long) value) < ((long) Integer.MAX_VALUE + 1) ? ((long) value + 1) : value;
332 | case TILEDB_FLOAT32:
333 | return ((float) value) < Float.MAX_VALUE ? Math.nextUp((float) value) : value;
334 | case TILEDB_FLOAT64:
335 | return ((double) value) < Double.MAX_VALUE ? Math.nextUp((double) value) : value;
336 | case TILEDB_STRING_ASCII:
337 | return stringPartitioner.nextStr((String) value);
338 | default:
339 | throw new TileDBError("Unsupported TileDB Datatype enum: " + type);
340 | }
341 | }
342 |
343 | /**
344 | * Returns v - eps, where eps is the smallest value for the datatype such that v - eps < v.
345 | */
346 | public static Object subtractEpsilon(Object value, Datatype type)
347 | throws TileDBError
348 | {
349 | switch (type) {
350 | case TILEDB_CHAR:
351 | case TILEDB_INT8:
352 | return ((byte) value) > Byte.MIN_VALUE ? ((byte) value - 1) : value;
353 | case TILEDB_INT16:
354 | return ((short) value) > Short.MIN_VALUE ? ((short) value - 1) : value;
355 | case TILEDB_INT32:
356 | return ((int) value) > Integer.MIN_VALUE ? ((int) value - 1) : value;
357 | case TILEDB_INT64:
358 | return ((long) value) > Long.MIN_VALUE ? ((long) value - 1) : value;
359 | case TILEDB_UINT8:
360 | return ((short) value) > ((short) Byte.MIN_VALUE - 1) ? ((short) value - 1) : value;
361 | case TILEDB_UINT16:
362 | return ((int) value) > ((int) Short.MIN_VALUE - 1) ? ((int) value - 1) : value;
363 | case TILEDB_UINT32:
364 | return ((long) value) > ((long) Integer.MIN_VALUE - 1) ? ((long) value - 1) : value;
365 | case TILEDB_DATETIME_AS:
366 | case TILEDB_DATETIME_FS:
367 | case TILEDB_DATETIME_PS:
368 | case TILEDB_DATETIME_NS:
369 | case TILEDB_DATETIME_US:
370 | case TILEDB_DATETIME_MS:
371 | case TILEDB_DATETIME_SEC:
372 | case TILEDB_DATETIME_MIN:
373 | case TILEDB_DATETIME_HR:
374 | case TILEDB_DATETIME_DAY:
375 | case TILEDB_DATETIME_WEEK:
376 | case TILEDB_DATETIME_MONTH:
377 | case TILEDB_DATETIME_YEAR:
378 | case TILEDB_UINT64:
379 | return ((long) value) > ((long) Integer.MIN_VALUE - 1) ? ((long) value - 1) : value;
380 | case TILEDB_FLOAT32:
381 | return ((float) value) > Float.MIN_VALUE ? Math.nextDown((float) value) : value;
382 | case TILEDB_FLOAT64:
383 | return ((double) value) > Double.MIN_VALUE ? Math.nextDown((double) value) : value;
384 | case TILEDB_STRING_ASCII:
385 | return stringPartitioner.previousStr((String) value);
386 | default:
387 | throw new TileDBError("Unsupported TileDB Datatype enum: " + type);
388 | }
389 | }
390 | }
391 |
--------------------------------------------------------------------------------
/src/main/resources/services/io.trino.spi.Plugin:
--------------------------------------------------------------------------------
1 | io.trino.plugin.tiledb.TileDBPlugin
--------------------------------------------------------------------------------
/src/modernizer/violations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | java/lang/Class.newInstance:()Ljava/lang/Object;
5 | 1.1
6 | Prefer Class.getConstructor().newInstance()
7 |
8 |
9 |
10 | java/lang/String.toLowerCase:()Ljava/lang/String;
11 | 1.1
12 | Prefer String.toLowerCase(java.util.Locale)
13 |
14 |
15 |
16 | com/google/common/primitives/Ints.checkedCast:(J)I
17 | 1.8
18 | Prefer Math.toIntExact(long)
19 |
20 |
21 |
22 | org/testng/Assert.assertEquals:(Ljava/lang/Iterable;Ljava/lang/Iterable;)V
23 | 1.8
24 | Use io.trino.testing.assertions.Assert.assertEquals due to TestNG #543
25 |
26 |
27 |
28 | org/testng/Assert.assertEquals:(Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/String;)V
29 | 1.8
30 | Use io.trino.testing.assertions.Assert.assertEquals due to TestNG #543
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/test/java/io/trino/plugin/tiledb/TestTileDBConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package io.trino.plugin.tiledb;
15 |
16 | import com.google.common.collect.ImmutableMap;
17 | import org.testng.annotations.Test;
18 |
19 | import java.util.Map;
20 |
21 | import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping;
22 | import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults;
23 | import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults;
24 |
25 | public class TestTileDBConfig
26 | {
27 | @Test
28 | public void testDefaults()
29 | {
30 | assertRecordedDefaults(recordDefaults(TileDBConfig.class)
31 | .setArrayURIs(null)
32 | .setReadBufferSize(10485760)
33 | .setWriteBufferSize(1048576)
34 | .setAwsAccessKeyId(null)
35 | .setAwsSecretAccessKey(null)
36 | .setTileDBConfig(null));
37 | }
38 |
39 | @Test
40 | public void testExplicitPropertyMappings()
41 | {
42 | Map properties = new ImmutableMap.Builder()
43 | .put("array-uris", "file:///test")
44 | .put("read-buffer-size", "10")
45 | .put("write-buffer-size", "100")
46 | .put("aws-access-key-id", "")
47 | .put("aws-secret-access-key", "")
48 | .put("tiledb-config", "").build();
49 |
50 | TileDBConfig expected = null;
51 | expected = new TileDBConfig()
52 | .setArrayURIs("file:///test")
53 | .setReadBufferSize(10)
54 | .setWriteBufferSize(100)
55 | .setAwsAccessKeyId("")
56 | .setAwsSecretAccessKey("")
57 | .setTileDBConfig("");
58 | assertFullMapping(properties, expected);
59 | }
60 |
61 | @Test
62 | public void testExplicitPropertyMappingsWithMultipleArrays()
63 | {
64 | Map properties = new ImmutableMap.Builder()
65 | .put("array-uris", "file:///test,s3:///test-bucket/array")
66 | .put("read-buffer-size", "1048576")
67 | .put("write-buffer-size", "104857")
68 | .put("aws-access-key-id", "123")
69 | .put("aws-secret-access-key", "abc")
70 | .put("tiledb-config", "key1=value1,key2=value2").build();
71 |
72 | TileDBConfig expected = null;
73 | expected = new TileDBConfig()
74 | .setArrayURIs("file:///test,s3:///test-bucket/array")
75 | .setReadBufferSize(1048576)
76 | .setWriteBufferSize(104857)
77 | .setAwsAccessKeyId("123")
78 | .setAwsSecretAccessKey("abc")
79 | .setTileDBConfig("key1=value1,key2=value2");
80 | assertFullMapping(properties, expected);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/test/java/io/trino/plugin/tiledb/TestTileDBIntegrationSmokeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package io.trino.plugin.tiledb;
15 |
16 | import io.airlift.tpch.TpchTable;
17 | import io.tiledb.java.api.Context;
18 | import io.tiledb.java.api.TileDBError;
19 | import io.tiledb.java.api.TileDBObject;
20 | import io.trino.spi.TrinoException;
21 | import io.trino.spi.type.VarcharType;
22 | import io.trino.testing.AbstractTestQueries;
23 | import io.trino.testing.MaterializedResult;
24 | import io.trino.testing.QueryRunner;
25 | import org.gaul.modernizer_maven_annotations.SuppressModernizer;
26 | import org.testng.annotations.AfterClass;
27 | import org.testng.annotations.Test;
28 |
29 | import static io.trino.plugin.tiledb.TileDBErrorCode.TILEDB_UNEXPECTED_ERROR;
30 | import static io.trino.spi.type.VarcharType.VARCHAR;
31 | import static org.assertj.core.api.Assertions.assertThat;
32 | import static org.testng.Assert.assertEquals;
33 |
34 | @SuppressModernizer
35 | public class TestTileDBIntegrationSmokeTest
36 | extends AbstractTestQueries
37 | {
38 | public TestTileDBIntegrationSmokeTest()
39 | {
40 | super();
41 | }
42 |
43 | protected boolean isParameterizedVarcharSupported()
44 | {
45 | return false;
46 | }
47 |
48 | @Override
49 | protected QueryRunner createQueryRunner()
50 | throws Exception
51 | {
52 | return TileDBQueryRunner.createTileDBQueryRunner();
53 | }
54 |
55 | @Override
56 | public void testShowColumns()
57 | {
58 | MaterializedResult actual = this.computeActual("SHOW COLUMNS FROM orders");
59 | MaterializedResult expected = MaterializedResult.resultBuilder(this.getSession(), VarcharType.VARCHAR, VarcharType.VARCHAR, VarcharType.VARCHAR, VarcharType.VARCHAR)
60 | .row("orderkey", "bigint", "", "Dimension")
61 | .row("custkey", "bigint", "", "Dimension")
62 | .row("orderstatus", "varchar(1)", "", "Attribute")
63 | .row("totalprice", "double", "", "Attribute")
64 | .row("orderdate", "date", "", "Attribute")
65 | .row("orderpriority", "varchar", "", "Attribute")
66 | .row("clerk", "varchar", "", "Attribute")
67 | .row("shippriority", "integer", "", "Attribute")
68 | .row(new Object[]{"comment", "varchar", "", "Attribute"}).build();
69 | assertThat(actual.equals(expected));
70 | }
71 |
72 | @Test
73 | public void testDescribeTable()
74 | {
75 | MaterializedResult actualColumns = computeActual("DESC orders").toTestTypes();
76 | MaterializedResult expectedColumns = getExpectedOrdersTableDescription(isParameterizedVarcharSupported());
77 | assertEquals(actualColumns, expectedColumns);
78 | }
79 |
80 | @Test
81 | public void testShowCreateTable()
82 | {
83 | assertThat((String) computeActual("SHOW CREATE TABLE orders").getOnlyValue())
84 | // If the connector reports additional column properties, the expected value needs to be adjusted in the test subclass
85 | .matches("CREATE TABLE tiledb.tiledb.orders \\Q(\n" +
86 | " orderkey bigint COMMENT 'Dimension',\n" +
87 | " custkey bigint COMMENT 'Dimension',\n" +
88 | " orderstatus varchar(1) COMMENT 'Attribute',\n" +
89 | " totalprice double COMMENT 'Attribute',\n" +
90 | " orderdate date COMMENT 'Attribute',\n" +
91 | " orderpriority varchar COMMENT 'Attribute',\n" +
92 | " clerk varchar COMMENT 'Attribute',\n" +
93 | " shippriority integer COMMENT 'Attribute',\n" +
94 | " comment varchar COMMENT 'Attribute'\n" +
95 | ")");
96 | }
97 |
98 | @AfterClass(alwaysRun = true)
99 | public final void destroy()
100 | throws TileDBError
101 | {
102 | Context context = new Context();
103 | for (TpchTable> table : TpchTable.getTables()) {
104 | try {
105 | TileDBObject.remove(context, table.getTableName());
106 | }
107 | catch (TileDBError tileDBError) {
108 | throw new TrinoException(TILEDB_UNEXPECTED_ERROR, tileDBError);
109 | }
110 | }
111 | context.close();
112 | }
113 |
114 | private MaterializedResult getExpectedOrdersTableDescription(boolean parametrizedVarchar)
115 | {
116 | if (parametrizedVarchar) {
117 | return MaterializedResult.resultBuilder(getQueryRunner().getDefaultSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR)
118 | .row("orderkey", "bigint", "", "Dimension")
119 | .row("custkey", "bigint", "", "Dimension")
120 | .row("orderstatus", "varchar(1)", "", "Attribute")
121 | .row("totalprice", "double", "", "Attribute")
122 | .row("orderdate", "date", "", "Attribute")
123 | .row("orderpriority", "varchar(15)", "", "Attribute")
124 | .row("clerk", "varchar(15)", "", "Attribute")
125 | .row("shippriority", "integer", "", "Attribute")
126 | .row("comment", "varchar(79)", "", "Attribute")
127 | .build();
128 | }
129 | else {
130 | return MaterializedResult.resultBuilder(getQueryRunner().getDefaultSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR)
131 | .row("orderkey", "bigint", "", "Dimension")
132 | .row("custkey", "bigint", "", "Dimension")
133 | .row("orderstatus", "varchar(1)", "", "Attribute")
134 | .row("totalprice", "double", "", "Attribute")
135 | .row("orderdate", "date", "", "Attribute")
136 | .row("orderpriority", "varchar", "", "Attribute")
137 | .row("clerk", "varchar", "", "Attribute")
138 | .row("shippriority", "integer", "", "Attribute")
139 | .row("comment", "varchar", "", "Attribute")
140 | .build();
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/src/test/java/io/trino/plugin/tiledb/TestTileDBPlugin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package io.trino.plugin.tiledb;
15 |
16 | import com.google.common.collect.ImmutableMap;
17 | import io.trino.spi.Plugin;
18 | import io.trino.spi.connector.ConnectorFactory;
19 | import io.trino.testing.TestingConnectorContext;
20 | import org.testng.annotations.Test;
21 |
22 | import java.nio.file.Path;
23 | import java.nio.file.Paths;
24 |
25 | import static com.google.common.collect.Iterables.getOnlyElement;
26 |
27 | public class TestTileDBPlugin
28 | {
29 | @Test
30 | public void testCreateConnector()
31 | {
32 | Plugin plugin = new TileDBPlugin();
33 | ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
34 | Path testArray = Paths.get("src", "test", "resources", "tiledb_arrays", "dense_global");
35 | factory.create("test", ImmutableMap.of("array-uris", testArray.toString()), new TestingConnectorContext());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/io/trino/plugin/tiledb/TileDBQueryRunner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package io.trino.plugin.tiledb;
15 |
16 | import com.google.common.collect.ImmutableList;
17 | import com.google.common.collect.ImmutableMap;
18 | import io.airlift.log.Logger;
19 | import io.airlift.tpch.TpchTable;
20 | import io.tiledb.java.api.Context;
21 | import io.tiledb.java.api.TileDBError;
22 | import io.trino.Session;
23 | import io.trino.metadata.QualifiedObjectName;
24 | import io.trino.plugin.tpch.TpchPlugin;
25 | import io.trino.testing.DistributedQueryRunner;
26 | import io.trino.testing.QueryRunner;
27 | import org.intellij.lang.annotations.Language;
28 |
29 | import java.io.File;
30 | import java.util.ArrayList;
31 | import java.util.List;
32 | import java.util.Map;
33 |
34 | import static io.airlift.testing.Closeables.closeAllSuppress;
35 | import static io.airlift.units.Duration.nanosSince;
36 | import static io.tiledb.java.api.Array.exists;
37 | import static io.trino.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME;
38 | import static io.trino.testing.TestingSession.testSessionBuilder;
39 | import static java.lang.String.format;
40 | import static java.util.concurrent.TimeUnit.SECONDS;
41 |
42 | public final class TileDBQueryRunner
43 | {
44 | private static final Logger LOG = Logger.get(TileDBQueryRunner.class);
45 | private static final String TPCH_SCHEMA = "tiledb";
46 | private static boolean tpchLoaded;
47 |
48 | private TileDBQueryRunner() {}
49 |
50 | public static DistributedQueryRunner createTileDBQueryRunner()
51 | throws Exception
52 | {
53 | return createTileDBQueryRunner(TpchTable.getTables(), ImmutableMap.of(), ImmutableMap.of(), new Context());
54 | }
55 |
56 | public static DistributedQueryRunner createTileDBQueryRunner(ImmutableMap sessionProperties)
57 | throws Exception
58 | {
59 | return createTileDBQueryRunner(TpchTable.getTables(), sessionProperties, ImmutableMap.of(), new Context());
60 | }
61 |
62 | public static DistributedQueryRunner createTileDBQueryRunner(TpchTable>... tables)
63 | throws Exception
64 | {
65 | return createTileDBQueryRunner(ImmutableList.copyOf(tables), ImmutableMap.of(), ImmutableMap.of(),
66 | new Context());
67 | }
68 |
69 | public static DistributedQueryRunner createTileDBQueryRunner(Iterable> tables,
70 | ImmutableMap sessionSystemProperties,
71 | Map extraProperties, Context ctx)
72 | throws Exception
73 | {
74 | Session.SessionBuilder sessionBuilder = testSessionBuilder()
75 | .setCatalog("tiledb")
76 | .setSchema("tiledb");
77 |
78 | for (Map.Entry entry : sessionSystemProperties.entrySet()) {
79 | sessionBuilder.setSystemProperty(entry.getKey(), entry.getValue());
80 | }
81 |
82 | Session session = sessionBuilder.build();
83 |
84 | DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).setNodeCount(4)
85 | .setExtraProperties(extraProperties).build();
86 |
87 | try {
88 | List existingTables = new ArrayList<>();
89 | List> tablesToCopy = new ArrayList<>();
90 | for (TpchTable> table : tables) {
91 | if ((new File(table.getTableName())).exists()) {
92 | existingTables.add(table.getTableName());
93 | }
94 | else {
95 | tablesToCopy.add(table);
96 | }
97 | }
98 |
99 | ImmutableMap.Builder propertiesBuilder = ImmutableMap.builder();
100 | if (!existingTables.isEmpty()) {
101 | propertiesBuilder.put("array-uris", String.join(",", existingTables));
102 | }
103 |
104 | Map properties = propertiesBuilder.build();
105 |
106 | queryRunner.installPlugin(new TileDBPlugin());
107 | queryRunner.createCatalog("tiledb", "tiledb", properties);
108 |
109 | queryRunner.installPlugin(new TpchPlugin());
110 | queryRunner.createCatalog("tpch", "tpch", ImmutableMap.of());
111 |
112 | if (!tpchLoaded) {
113 | copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, createSession(), tablesToCopy, ctx);
114 | tpchLoaded = true;
115 | }
116 |
117 | return queryRunner;
118 | }
119 | catch (Exception e) {
120 | closeAllSuppress(e, queryRunner);
121 | throw e;
122 | }
123 | }
124 |
125 | private static void copyTpchTables(
126 | QueryRunner queryRunner,
127 | String sourceCatalog,
128 | String sourceSchema,
129 | Session session,
130 | Iterable> tables,
131 | Context ctx)
132 | throws TileDBError
133 | {
134 | LOG.info("Loading data from %s.%s...", sourceCatalog, sourceSchema);
135 | long startTime = System.nanoTime();
136 | for (TpchTable> table : tables) {
137 | // Build test tables if they do not exist. Normally we should always rebuild them but for testing
138 | // it is helpful to not destroy them
139 | if (!(new File(table.getTableName())).exists() || !exists(ctx, table.getTableName())) {
140 | copyTable(queryRunner, sourceCatalog, session, sourceSchema, table);
141 | }
142 | }
143 | LOG.info("Loading from %s.%s complete in %s", sourceCatalog, sourceSchema, nanosSince(startTime).toString(SECONDS));
144 | }
145 |
146 | private static void copyTable(
147 | QueryRunner queryRunner,
148 | String catalog,
149 | Session session,
150 | String schema,
151 | TpchTable> table)
152 | {
153 | QualifiedObjectName source = new QualifiedObjectName(catalog, schema, table.getTableName());
154 | String target = table.getTableName();
155 |
156 | @Language("SQL")
157 | String createSQL;
158 | String insertSQL;
159 | switch (target) {
160 | case "customer":
161 | createSQL = format("CREATE TABLE %s (\n" +
162 | " custkey bigint WITH (dimension=true),\n" +
163 | " name varchar(25),\n" +
164 | " address varchar(40),\n" +
165 | " nationkey bigint,\n" +
166 | " phone varchar(15),\n" +
167 | " acctbal double,\n" +
168 | " mktsegment varchar(10),\n" +
169 | " comment varchar(117)\n" +
170 | " ) WITH (uri = '%s')", target, target);
171 | insertSQL = format("INSERT INTO %s (custkey, name, nationkey, address, phone, acctbal, mktsegment, comment) SELECT custkey, name, nationkey, address, phone, acctbal, mktsegment, comment FROM %s", target, source);
172 | break;
173 | case "lineitem":
174 | createSQL = format("CREATE TABLE %s(\n" +
175 | " orderkey bigint WITH (dimension=true),\n" +
176 | " partkey bigint WITH (dimension=true),\n" +
177 | " suppkey bigint WITH (dimension=true),\n" +
178 | " linenumber bigint WITH (dimension=true),\n" +
179 | " quantity double,\n" +
180 | " extendedprice double,\n" +
181 | " discount double,\n" +
182 | " tax double,\n" +
183 | " returnflag varchar(1),\n" +
184 | " linestatus varchar(1),\n" +
185 | " shipdate date,\n" +
186 | " commitdate date,\n" +
187 | " receiptdate date,\n" +
188 | " shipinstruct varchar(25),\n" +
189 | " shipmode varchar(10),\n" +
190 | " comment varchar(44)\n" +
191 | " ) WITH (uri = '%s')", target, target);
192 | insertSQL = format("INSERT INTO %s (orderkey, partkey, suppkey, linenumber, quantity, extendedprice, discount, tax, returnflag, linestatus, shipdate, commitdate, receiptdate, shipinstruct, shipmode, comment) SELECT orderkey, partkey, suppkey, linenumber, quantity, extendedprice, discount, tax, returnflag, linestatus, shipdate, commitdate, receiptdate, shipinstruct, shipmode, comment FROM %s", target, source);
193 | break;
194 | case "nation":
195 | createSQL = format("CREATE TABLE %s(\n" +
196 | " nationkey bigint WITH (dimension=true),\n" +
197 | " name varchar(25),\n" +
198 | " regionkey bigint,\n" +
199 | " comment varchar(152)\n" +
200 | " ) WITH (uri = '%s')", target, target);
201 | insertSQL = format("INSERT INTO %s (nationkey, name, regionkey, comment) SELECT nationkey, name, regionkey, comment FROM %s", target, source);
202 | break;
203 | case "orders":
204 | createSQL = format("CREATE TABLE %s(\n" +
205 | " orderkey bigint WITH (dimension=true),\n" +
206 | " custkey bigint WITH (dimension=true),\n" +
207 | " orderstatus varchar(1),\n" +
208 | " totalprice double,\n" +
209 | " orderdate date,\n" +
210 | " orderpriority varchar(15),\n" +
211 | " clerk varchar(15),\n" +
212 | " shippriority integer,\n" +
213 | " comment varchar(79)\n" +
214 | " ) WITH (uri = '%s')", target, target);
215 | insertSQL = format("INSERT INTO %s (orderkey, custkey, orderstatus, totalprice, orderdate, orderpriority, clerk, shippriority, comment) SELECT orderkey, custkey, orderstatus, totalprice, orderdate, orderpriority, clerk, shippriority, comment FROM %s", target, source);
216 | break;
217 | case "part":
218 | createSQL = format("CREATE TABLE %s(\n" +
219 | " partkey bigint WITH (dimension=true),\n" +
220 | " name varchar(55),\n" +
221 | " mfgr varchar(25),\n" +
222 | " brand varchar(10),\n" +
223 | " type varchar(25),\n" +
224 | " size integer,\n" +
225 | " container varchar(10),\n" +
226 | " retailprice double,\n" +
227 | " comment varchar(23)\n" +
228 | " ) WITH (uri = '%s')", target, target);
229 | insertSQL = format("INSERT INTO %s (partkey, name, mfgr, brand, type, size, container, retailprice, comment) SELECT partkey, name, mfgr, brand, type, size, container, retailprice, comment FROM %s", target, source);
230 | break;
231 | case "partsupp":
232 | createSQL = format("CREATE TABLE %s(\n" +
233 | " partkey bigint WITH (dimension=true),\n" +
234 | " suppkey bigint WITH (dimension=true),\n" +
235 | " availqty integer,\n" +
236 | " supplycost double,\n" +
237 | " comment varchar(199)\n" +
238 | " ) WITH (uri = '%s')", target, target);
239 | insertSQL = format("INSERT INTO %s (partkey, suppkey, availqty, supplycost, comment) SELECT partkey, suppkey, availqty, supplycost, comment FROM %s", target, source);
240 | break;
241 | case "region":
242 | createSQL = format("CREATE TABLE %s(\n" +
243 | " regionkey bigint WITH (dimension=true),\n" +
244 | " name varchar(25),\n" +
245 | " comment varchar(152)\n" +
246 | " ) WITH (uri = '%s')", target, target);
247 | insertSQL = format("INSERT INTO %s (regionkey, name, comment) SELECT regionkey, name, comment FROM %s", target, source);
248 | break;
249 | case "supplier":
250 | createSQL = format("CREATE TABLE %s(\n" +
251 | " suppkey bigint WITH (dimension=true),\n" +
252 | " name varchar(25),\n" +
253 | " address varchar(40),\n" +
254 | " nationkey bigint,\n" +
255 | " phone varchar(15),\n" +
256 | " acctbal double,\n" +
257 | " comment varchar(101)\n" +
258 | " ) WITH (uri = '%s')", target, target);
259 | insertSQL = format("INSERT INTO %s (suppkey, name, address, nationkey, phone, acctbal, comment) SELECT suppkey, name, address, nationkey, phone, acctbal, comment FROM %s", target, source);
260 | break;
261 | default:
262 | createSQL = format("CREATE TABLE %s LIKE %s WITH (uri = '%s')", target, source, target);
263 | insertSQL = format("INSERT INTO %s SELECT * FROM %s", target, source);
264 | break;
265 | }
266 |
267 | LOG.info("Running create table for %s", target);
268 | LOG.info("%s", createSQL);
269 | queryRunner.execute(createSQL);
270 | LOG.info("Running import for %s", target);
271 | LOG.info("%s", insertSQL);
272 | long start = System.nanoTime();
273 | long rows = queryRunner.execute(insertSQL).getUpdateCount().getAsLong();
274 | LOG.info("Imported %s rows for %s in %s", rows, target, nanosSince(start));
275 | }
276 |
277 | /*public static void main(String[] args)
278 | throws Exception
279 | {
280 | Logging.initialize();
281 | DistributedQueryRunner queryRunner = createTileDBQueryRunner(ImmutableList.copyOf(ORDERS), ImmutableMap.of("http-server.http.port", "8080"));
282 | Thread.sleep(10);
283 | Logger log = Logger.get(TileDBQueryRunner.class);
284 | log.info("======== SERVER STARTED ========");
285 | log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl());
286 | }*/
287 |
288 | public static Session createSession()
289 | {
290 | return testSessionBuilder()
291 | .setCatalog("tiledb")
292 | .setSchema(TPCH_SCHEMA)
293 | .build();
294 | }
295 | }
296 |
--------------------------------------------------------------------------------
/src/test/resources/tiledb_arrays/dense_global/__array_schema.tdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TileDB-Inc/TileDB-Trino/09454705bfb1fb6313b1af6b07bb2d7bd31ec606/src/test/resources/tiledb_arrays/dense_global/__array_schema.tdb
--------------------------------------------------------------------------------
/src/test/resources/tiledb_arrays/dense_global/__c2076894fd614aac824cfc6cc0e1b754_1538424663019/__fragment_metadata.tdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TileDB-Inc/TileDB-Trino/09454705bfb1fb6313b1af6b07bb2d7bd31ec606/src/test/resources/tiledb_arrays/dense_global/__c2076894fd614aac824cfc6cc0e1b754_1538424663019/__fragment_metadata.tdb
--------------------------------------------------------------------------------
/src/test/resources/tiledb_arrays/dense_global/__c2076894fd614aac824cfc6cc0e1b754_1538424663019/a.tdb:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/test/resources/tiledb_arrays/dense_global/__lock.tdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TileDB-Inc/TileDB-Trino/09454705bfb1fb6313b1af6b07bb2d7bd31ec606/src/test/resources/tiledb_arrays/dense_global/__lock.tdb
--------------------------------------------------------------------------------
/src/test/resources/tiledb_arrays/sparse_global/__5d43f0e2b2f34675abaa642ef0f6128e_1538424648583/__coords.tdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TileDB-Inc/TileDB-Trino/09454705bfb1fb6313b1af6b07bb2d7bd31ec606/src/test/resources/tiledb_arrays/sparse_global/__5d43f0e2b2f34675abaa642ef0f6128e_1538424648583/__coords.tdb
--------------------------------------------------------------------------------
/src/test/resources/tiledb_arrays/sparse_global/__5d43f0e2b2f34675abaa642ef0f6128e_1538424648583/__fragment_metadata.tdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TileDB-Inc/TileDB-Trino/09454705bfb1fb6313b1af6b07bb2d7bd31ec606/src/test/resources/tiledb_arrays/sparse_global/__5d43f0e2b2f34675abaa642ef0f6128e_1538424648583/__fragment_metadata.tdb
--------------------------------------------------------------------------------
/src/test/resources/tiledb_arrays/sparse_global/__5d43f0e2b2f34675abaa642ef0f6128e_1538424648583/a.tdb:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/test/resources/tiledb_arrays/sparse_global/__array_schema.tdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TileDB-Inc/TileDB-Trino/09454705bfb1fb6313b1af6b07bb2d7bd31ec606/src/test/resources/tiledb_arrays/sparse_global/__array_schema.tdb
--------------------------------------------------------------------------------
/src/test/resources/tiledb_arrays/sparse_global/__lock.tdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TileDB-Inc/TileDB-Trino/09454705bfb1fb6313b1af6b07bb2d7bd31ec606/src/test/resources/tiledb_arrays/sparse_global/__lock.tdb
--------------------------------------------------------------------------------