-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-11827] [SQL] Adding java.math.BigInteger support in Java type inference for POJOs and Java collections #10125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
3b44c59
18b4a31
4f4d1c8
f5f0cbe
d8b2edb
196b6c6
f37a01e
bb5b01f
bde5820
5f7cd96
ae0be70
741daff
893a49a
bbed47a
536d20c
54cfc24
4bbe1fd
b2dd795
de7757d
db4bb48
8c3e5da
a0eaa40
b1527b7
b26412e
43faed3
3b4e360
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,7 @@ object DecimalType extends AbstractDataType { | |
| val MAX_SCALE = 38 | ||
| val SYSTEM_DEFAULT: DecimalType = DecimalType(MAX_PRECISION, 18) | ||
| val USER_DEFAULT: DecimalType = DecimalType(10, 0) | ||
| val BIGINT_DEFAULT: DecimalType = DecimalType(MAX_PRECISION, 0) | ||
|
||
|
|
||
| // The decimal types compatible with other numeric types | ||
| private[sql] val ByteDecimal = DecimalType(3, 0) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ | |
| import java.net.URISyntaxException; | ||
| import java.net.URL; | ||
| import java.util.*; | ||
| import java.math.BigInteger; | ||
| import java.math.BigDecimal; | ||
|
|
||
| import scala.collection.JavaConverters; | ||
| import scala.collection.Seq; | ||
|
|
@@ -130,6 +132,7 @@ public static class Bean implements Serializable { | |
| private Integer[] b = { 0, 1 }; | ||
| private Map<String, int[]> c = ImmutableMap.of("hello", new int[] { 1, 2 }); | ||
| private List<String> d = Arrays.asList("floppy", "disk"); | ||
| private BigInteger e = new BigInteger("1234567"); | ||
|
|
||
| public double getA() { | ||
| return a; | ||
|
|
@@ -146,6 +149,8 @@ public Map<String, int[]> getC() { | |
| public List<String> getD() { | ||
| return d; | ||
| } | ||
|
|
||
| public BigInteger getE() { return e; } | ||
| } | ||
|
|
||
| void validateDataFrameWithBeans(Bean bean, Dataset<Row> df) { | ||
|
|
@@ -163,7 +168,9 @@ void validateDataFrameWithBeans(Bean bean, Dataset<Row> df) { | |
| Assert.assertEquals( | ||
| new StructField("d", new ArrayType(DataTypes.StringType, true), true, Metadata.empty()), | ||
| schema.apply("d")); | ||
| Row first = df.select("a", "b", "c", "d").first(); | ||
| Assert.assertEquals(new StructField("e", DataTypes.createDecimalType(38,0), true, Metadata.empty()), | ||
| schema.apply("e")); | ||
| Row first = df.select("a", "b", "c", "d","e").first(); | ||
|
||
| Assert.assertEquals(bean.getA(), first.getDouble(0), 0.0); | ||
| // Now Java lists and maps are converted to Scala Seq's and Map's. Once we get a Seq below, | ||
| // verify that it has the expected length, and contains expected elements. | ||
|
|
@@ -182,6 +189,8 @@ void validateDataFrameWithBeans(Bean bean, Dataset<Row> df) { | |
| for (int i = 0; i < d.length(); i++) { | ||
| Assert.assertEquals(bean.getD().get(i), d.apply(i)); | ||
| } | ||
| // Java.math.BigInteger is equavient to Spark Decimal(38,0) | ||
| Assert.assertEquals(new BigDecimal(bean.getE()), first.getDecimal(4).setScale(0)); | ||
|
||
| } | ||
|
|
||
| @Test | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you hold on until #13008? Then we can revert this change as
CatalystTypeConverteris not used when creating DataFrame.