Repository: drill Updated Branches: refs/heads/master 3442215fd -> a84f7b9e8
DRILL-2338: Fix Decimal38/Decimal28 vector's get() to copy the scale and precision into the holder Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/a84f7b9e Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/a84f7b9e Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/a84f7b9e Branch: refs/heads/master Commit: a84f7b9e88b1827e6b4da8cdd25c6d4f12dcdadc Parents: 3442215 Author: Mehant Baid <meha...@gmail.com> Authored: Fri Feb 27 19:21:51 2015 -0800 Committer: Mehant Baid <meha...@gmail.com> Committed: Mon Mar 2 11:13:27 2015 -0800 ---------------------------------------------------------------------- .../codegen/templates/FixedValueVectors.java | 12 ++-------- .../physical/impl/writer/TestParquetWriter.java | 25 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/a84f7b9e/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java b/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java index b5011e6..6cea8c8 100644 --- a/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java +++ b/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java @@ -394,17 +394,8 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F <#elseif (minor.class == "Decimal28Sparse") || (minor.class == "Decimal38Sparse") || (minor.class == "Decimal28Dense") || (minor.class == "Decimal38Dense")> public void get(int index, ${minor.class}Holder holder) { - holder.start = index * ${type.width}; - holder.buffer = data; - - /* The buffer within the value vector is little endian. - * For the dense representation though, we use big endian - * byte ordering (internally). This is because we shift bits to the right and - * big endian ordering makes sense for this purpose. So we have to deal with - * the sign bit for the two representation in a slightly different fashion - */ holder.scale = getField().getScale(); holder.precision = getField().getPrecision(); } @@ -412,8 +403,9 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F public void get(int index, Nullable${minor.class}Holder holder) { holder.isSet = 1; holder.start = index * ${type.width}; - holder.buffer = data; + holder.scale = getField().getScale(); + holder.precision = getField().getPrecision(); } @Override http://git-wip-us.apache.org/repos/asf/drill/blob/a84f7b9e/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/writer/TestParquetWriter.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/writer/TestParquetWriter.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/writer/TestParquetWriter.java index 7298f28..76328c6 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/writer/TestParquetWriter.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/writer/TestParquetWriter.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals; import java.io.UnsupportedEncodingException; import java.lang.reflect.Array; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -360,6 +361,30 @@ public class TestParquetWriter extends BaseTestQuery { compareParquetReadersColumnar("wr_returning_customer_sk", "dfs.`/tmp/web_returns`"); } + @Test + public void testWriteDecimal() throws Exception { + String outputTable = "decimal_test"; + Path path = new Path("/tmp/" + outputTable); + if (fs.exists(path)) { + fs.delete(path, true); + } + String ctas = String.format("use dfs.tmp; " + + "create table %s as select " + + "cast('1.2' as decimal(38, 2)) col1, cast('1.2' as decimal(28, 2)) col2 " + + "from cp.`employee.json` limit 1", outputTable); + + test(ctas); + + BigDecimal result = new BigDecimal("1.20"); + + testBuilder() + .unOrdered() + .sqlQuery(String.format("select col1, col2 from %s ", outputTable)) + .baselineColumns("col1", "col2") + .baselineValues(result, result) + .go(); + } + public void runTestAndValidate(String selection, String validationSelection, String inputTable, String outputFile) throws Exception { Path path = new Path("/tmp/" + outputFile);