Skip to content

Commit

Permalink
DRILL-2338: Fix Decimal38/Decimal28 vector's get() to copy the scale …
Browse files Browse the repository at this point in the history
…and precision into the holder
  • Loading branch information
mehant committed Mar 2, 2015
1 parent 3442215 commit a84f7b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
12 changes: 2 additions & 10 deletions exec/java-exec/src/main/codegen/templates/FixedValueVectors.java
Expand Up @@ -394,26 +394,18 @@ public StringBuilder getAsStringBuilder(int index) {
<#elseif (minor.class == "Decimal28Sparse") || (minor.class == "Decimal38Sparse") || (minor.class == "Decimal28Dense") || (minor.class == "Decimal38Dense")> <#elseif (minor.class == "Decimal28Sparse") || (minor.class == "Decimal38Sparse") || (minor.class == "Decimal28Dense") || (minor.class == "Decimal38Dense")>


public void get(int index, ${minor.class}Holder holder) { public void get(int index, ${minor.class}Holder holder) {

holder.start = index * ${type.width}; holder.start = index * ${type.width};

holder.buffer = data; 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.scale = getField().getScale();
holder.precision = getField().getPrecision(); holder.precision = getField().getPrecision();
} }


public void get(int index, Nullable${minor.class}Holder holder) { public void get(int index, Nullable${minor.class}Holder holder) {
holder.isSet = 1; holder.isSet = 1;
holder.start = index * ${type.width}; holder.start = index * ${type.width};

holder.buffer = data; holder.buffer = data;
holder.scale = getField().getScale();
holder.precision = getField().getPrecision();
} }


@Override @Override
Expand Down
Expand Up @@ -21,6 +21,7 @@


import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
Expand Down Expand Up @@ -360,6 +361,30 @@ public void testParquetReadWebReturns() throws Exception {
compareParquetReadersColumnar("wr_returning_customer_sk", "dfs.`/tmp/web_returns`"); 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 { public void runTestAndValidate(String selection, String validationSelection, String inputTable, String outputFile) throws Exception {


Path path = new Path("/tmp/" + outputFile); Path path = new Path("/tmp/" + outputFile);
Expand Down

0 comments on commit a84f7b9

Please sign in to comment.