-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Spark: Use decimal128 #13665
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
Spark: Use decimal128 #13665
Changes from all commits
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 |
|---|---|---|
|
|
@@ -21,7 +21,11 @@ | |
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.io.IOException; | ||
| import java.math.BigDecimal; | ||
| import java.nio.file.Files; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
| import org.apache.iceberg.ParameterizedTestExtension; | ||
| import org.apache.iceberg.Table; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
|
|
@@ -172,6 +176,34 @@ public void showView() { | |
| sql("DROP VIEW %s", "test"); | ||
| } | ||
|
|
||
| @TestTemplate | ||
| public void testDecimalColumn() { | ||
| int rows = 100; | ||
| String tableName = tableName("decimal_table1"); | ||
| // Create table with a single DECIMAL column | ||
| sql("CREATE TABLE IF NOT EXISTS %s (amount DECIMAL(17, 5)) USING iceberg", tableName); | ||
| sql("TRUNCATE TABLE %s", tableName); | ||
|
|
||
| // Build and execute the INSERT statement | ||
| sql( | ||
| "INSERT INTO %s VALUES %s", | ||
| tableName, | ||
| IntStream.range(0, rows).mapToObj(i -> "(" + i + ")").collect(Collectors.joining(","))); | ||
|
|
||
| // Build expected results | ||
| List<Object[]> expected = | ||
| IntStream.range(0, rows) | ||
| .mapToObj(i -> new Object[] {new BigDecimal(i + ".00000")}) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| // Query and validate | ||
| List<Object[]> actual = sql("SELECT * FROM %s", tableName); | ||
| for (int i = 0; i < expected.size(); i++) { | ||
| System.out.println(actual.get(i)[0]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this? |
||
| assertEquals("Mismatch at row " + i, expected, actual); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you comparing row by row? |
||
| } | ||
| } | ||
|
|
||
| private Table getTable(String name) { | ||
| return validationCatalog.loadTable(TableIdentifier.of("default", name)); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,11 @@ | |
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.io.IOException; | ||
| import java.math.BigDecimal; | ||
| import java.nio.file.Files; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
| import org.apache.iceberg.ParameterizedTestExtension; | ||
| import org.apache.iceberg.Table; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
|
|
@@ -172,6 +176,34 @@ public void showView() { | |
| sql("DROP VIEW %s", "test"); | ||
| } | ||
|
|
||
| @TestTemplate | ||
| public void testDecimalColumn() { | ||
| int rows = 100; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to try some other values - The range of integers between 513 and 1024 is likely to show a mismatch between the byte array base dBigInteger/BigDecimal encoding and the 128 bit native integer. |
||
| String tableName = tableName("decimal_table1"); | ||
| // Create table with a single DECIMAL column | ||
| sql("CREATE TABLE IF NOT EXISTS %s (amount DECIMAL(17, 5)) USING iceberg", tableName); | ||
| sql("TRUNCATE TABLE %s", tableName); | ||
|
|
||
| // Build and execute the INSERT statement | ||
| sql( | ||
| "INSERT INTO %s VALUES %s", | ||
| tableName, | ||
| IntStream.range(0, rows).mapToObj(i -> "(" + i + ")").collect(Collectors.joining(","))); | ||
|
|
||
| // Build expected results | ||
| List<Object[]> expected = | ||
| IntStream.range(0, rows) | ||
| .mapToObj(i -> new Object[] {new BigDecimal(i + ".00000")}) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| // Query and validate | ||
| List<Object[]> actual = sql("SELECT * FROM %s", tableName); | ||
| for (int i = 0; i < expected.size(); i++) { | ||
| System.out.println(actual.get(i)[0]); | ||
| assertEquals("Mismatch at row " + i, expected, actual); | ||
| } | ||
| } | ||
|
|
||
| private Table getTable(String name) { | ||
| return validationCatalog.loadTable(TableIdentifier.of("default", name)); | ||
| } | ||
|
|
||
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.
Shall we use the class level field
this.tableNameinstead?then we will have the
@AfterEachcleanupsql("DROP TABLE IF EXISTS %s", tableName)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.
I think if we switch to class level field
this.tableName, then we don't need theTRUNCATE TABLEbelow.