|
16 | 16 | */
|
17 | 17 | package org.apache.livy.thriftserver.session;
|
18 | 18 |
|
19 |
| -import java.math.BigDecimal; |
20 | 19 | import java.nio.ByteBuffer;
|
21 | 20 | import java.util.ArrayList;
|
22 | 21 | import java.util.Arrays;
|
23 | 22 | import java.util.BitSet;
|
24 |
| -import java.util.Iterator; |
25 | 23 | import java.util.List;
|
26 |
| -import java.util.Spliterator; |
27 |
| -import java.util.Spliterators; |
28 |
| -import java.util.concurrent.atomic.AtomicInteger; |
29 |
| -import java.util.stream.Collectors; |
30 | 24 | import java.util.stream.Stream;
|
31 |
| -import java.util.stream.StreamSupport; |
32 |
| - |
33 |
| -import scala.Tuple2; |
34 |
| -import scala.collection.Map; |
35 |
| -import scala.collection.Seq; |
36 |
| - |
37 |
| -import org.apache.spark.sql.Row; |
38 |
| -import org.apache.spark.sql.types.StructField; |
39 | 25 |
|
40 | 26 | /**
|
41 | 27 | * Container for the contents of a single column in a result set.
|
@@ -180,7 +166,7 @@ public void add(Object value) {
|
180 | 166 | buffers[currentSize] = (byte[]) value;
|
181 | 167 | break;
|
182 | 168 | case STRING:
|
183 |
| - strings[currentSize] = toHiveString(value, false); |
| 169 | + strings[currentSize] = (String) value; |
184 | 170 | break;
|
185 | 171 | }
|
186 | 172 |
|
@@ -264,57 +250,6 @@ private void setNull(int index) {
|
264 | 250 | nulls[byteIdx] = (byte) (nulls[byteIdx] | (1 << bitIdx));
|
265 | 251 | }
|
266 | 252 |
|
267 |
| - /** |
268 |
| - * Converts a value from a Spark dataset into a string that looks like what Hive would |
269 |
| - * generate. Because Spark generates rows that contain Scala types for non-primitive |
270 |
| - * columns, this code depends on Scala and is thus succeptible to binary compatibility |
271 |
| - * changes in the Scala libraries. |
272 |
| - * |
273 |
| - * The supported types are described in Spark's SQL programming guide, in the table |
274 |
| - * listing the mapping of SQL types to Scala types. |
275 |
| - * |
276 |
| - * @param value The object to stringify. |
277 |
| - * @param quoteStrings Whether to wrap String instances in quotes. |
278 |
| - */ |
279 |
| - private String toHiveString(Object value, boolean quoteStrings) { |
280 |
| - if (quoteStrings && value instanceof String) { |
281 |
| - return "\"" + value + "\""; |
282 |
| - } else if (value instanceof BigDecimal) { |
283 |
| - return ((BigDecimal) value).stripTrailingZeros().toString(); |
284 |
| - } else if (value instanceof Map) { |
285 |
| - return stream(new ScalaIterator<>(((Map<?,?>) value).iterator())) |
286 |
| - .map(o -> toHiveString(o, true)) |
287 |
| - .sorted() |
288 |
| - .collect(Collectors.joining(",", "{", "}")); |
289 |
| - } else if (value instanceof Seq) { |
290 |
| - return stream(new ScalaIterator<>(((Seq<?>) value).iterator())) |
291 |
| - .map(o -> toHiveString(o, true)) |
292 |
| - .collect(Collectors.joining(",", "[", "]")); |
293 |
| - } else if (value instanceof Tuple2) { |
294 |
| - Tuple2 t = (Tuple2) value; |
295 |
| - return String.format("%s:%s", toHiveString(t._1(), true), toHiveString(t._2(), true)); |
296 |
| - } else if (value instanceof Row) { |
297 |
| - Row r = (Row) value; |
298 |
| - final StructField[] fields = r.schema().fields(); |
299 |
| - final AtomicInteger idx = new AtomicInteger(); |
300 |
| - |
301 |
| - return stream(new ScalaIterator<>(r.toSeq().iterator())) |
302 |
| - .map(o -> { |
303 |
| - String fname = fields[idx.getAndIncrement()].name(); |
304 |
| - String fval = toHiveString(o, true); |
305 |
| - return String.format("\"%s\":%s", fname, fval); |
306 |
| - }) |
307 |
| - .collect(Collectors.joining(",", "{", "}")); |
308 |
| - } else { |
309 |
| - return value.toString(); |
310 |
| - } |
311 |
| - } |
312 |
| - |
313 |
| - private Stream<?> stream(Iterator<?> it) { |
314 |
| - return StreamSupport.stream( |
315 |
| - Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED), false); |
316 |
| - } |
317 |
| - |
318 | 253 | private void ensureCapacity() {
|
319 | 254 | int nextSize = (currentSize + DEFAULT_SIZE);
|
320 | 255 | nextSize = nextSize - (nextSize % DEFAULT_SIZE);
|
|
0 commit comments