Java Code Examples for org.apache.arrow.vector.ValueVector#getValueCount()

The following examples show how to use org.apache.arrow.vector.ValueVector#getValueCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParquetResultListener.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void printColumnMajor(ValueVector vv) {
  if (ParquetRecordReaderTest.VERBOSE_DEBUG){
    System.out.println("\n" + vv.getField().getName());
  }
  for (int j = 0; j < vv.getValueCount(); j++) {
    if (ParquetRecordReaderTest.VERBOSE_DEBUG){
      Object o = vv.getObject(j);
      if (o instanceof byte[]) {
        try {
          o = new String((byte[])o, "UTF-8");
        } catch (UnsupportedEncodingException e) {
          throw new RuntimeException(e);
        }
      }
      System.out.print(Strings.padStart(o + "", 20, ' ') + " ");
      System.out.print(", " + (j % 25 == 0 ? "\n batch:" + batchCounter + " v:" + j + " - " : ""));
    }
  }
  if (ParquetRecordReaderTest.VERBOSE_DEBUG) {
    System.out.println("\n" + vv.getValueCount());
  }
}
 
Example 2
Source File: TestConvertFunctions.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
protected Object[] getRunResult(QueryType queryType, String planString) throws Exception {
  List<QueryDataBatch> resultList = testRunAndReturn(queryType, planString);

  List<Object> res = new ArrayList<>();
  RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
  for(QueryDataBatch result : resultList) {
    if (result.getData() != null) {
      loader.load(result.getHeader().getDef(), result.getData());
      ValueVector v = loader.iterator().next().getValueVector();
      for (int j = 0; j < v.getValueCount(); j++) {
        if  (v instanceof VarCharVector) {
          res.add(new String(((VarCharVector) v).get(j)));
        } else {
          res.add(v.getObject(j));
        }
      }
      loader.clear();
      result.release();
    }
  }

  return res.toArray();
}
 
Example 3
Source File: TestReverseImplicitCast.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void twoWayCast() throws Exception {

  // Function checks for casting from Float, Double to Decimal data types
  try (ClusterCoordinator clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
       SabotNode bit = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT, true);
       DremioClient client = new DremioClient(DEFAULT_SABOT_CONFIG, clusterCoordinator)) {
    // run query.
    bit.run();
    client.connect();
    List<QueryDataBatch> results = client.runQuery(com.dremio.exec.proto.UserBitShared.QueryType.PHYSICAL,
        Files.toString(FileUtils.getResourceAsFile("/functions/cast/two_way_implicit_cast.json"), Charsets.UTF_8));

    RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());

    QueryDataBatch batch = results.get(0);
    assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

    Iterator<VectorWrapper<?>> itr = batchLoader.iterator();

    ValueVector intValueVector = itr.next().getValueVector();
    ValueVector varcharValueVector = itr.next().getValueVector();

    for (int i = 0; i < intValueVector.getValueCount(); i++) {
      System.out.println(intValueVector.getObject(i));
      assertEquals(intValueVector.getObject(i), 10);
      System.out.println(varcharValueVector.getObject(i));
      assertEquals(varcharValueVector.getObject(i).toString(), "101");
    }

    batchLoader.clear();
    for (QueryDataBatch result : results) {
      result.release();
    }
  }
}
 
Example 4
Source File: BaseTestQuery.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
protected static String getValueInFirstRecord(String sql, String columnName)
    throws Exception {
  final List<QueryDataBatch> results = testSqlWithResults(sql);
  final RecordBatchLoader loader = new RecordBatchLoader(getSabotContext().getAllocator());
  final StringBuilder builder = new StringBuilder();
  final boolean silent = config != null && config.getBoolean(QueryTestUtil.TEST_QUERY_PRINTING_SILENT);

  for (final QueryDataBatch b : results) {
    if (!b.hasData()) {
      continue;
    }

    loader.load(b.getHeader().getDef(), b.getData());

    final VectorWrapper<?> vw;
    try {
        vw = loader.getValueAccessorById(
            VarCharVector.class,
            loader.getValueVectorId(SchemaPath.getSimplePath(columnName)).getFieldIds());
    } catch (Throwable t) {
      throw new Exception("Looks like you did not provide an explain plan query, please add EXPLAIN PLAN FOR to the beginning of your query.");
    }

    if (!silent) {
      System.out.println(vw.getValueVector().getField().getName());
    }
    final ValueVector vv = vw.getValueVector();
    for (int i = 0; i < vv.getValueCount(); i++) {
      final Object o = vv.getObject(i);
      builder.append(o);
      if (!silent) {
        System.out.println(o);
      }
    }
    loader.clear();
    b.release();
  }

  return builder.toString();
}
 
Example 5
Source File: TestParquetPhysicalPlan.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
  @Ignore
  public void testParseParquetPhysicalPlan() throws Exception {
    try (ClusterCoordinator clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
         SabotNode bit1 = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT, true); DremioClient client = new DremioClient(DEFAULT_SABOT_CONFIG, clusterCoordinator)) {
      bit1.run();
      client.connect();
      List<QueryDataBatch> results = client.runQuery(com.dremio.exec.proto.UserBitShared.QueryType.PHYSICAL, Resources.toString(Resources.getResource(fileName),Charsets.UTF_8));
      RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator());
      int count = 0;
      for (QueryDataBatch b : results) {
        System.out.println(String.format("Got %d results", b.getHeader().getRowCount()));
        count += b.getHeader().getRowCount();
        loader.load(b.getHeader().getDef(), b.getData());
        for (VectorWrapper vw : loader) {
          System.out.print(vw.getValueVector().getField().getName() + ": ");
          ValueVector vv = vw.getValueVector();
          for (int i = 0; i < vv.getValueCount(); i++) {
            Object o = vv.getObject(i);
            if (o instanceof byte[]) {
              System.out.print(" [" + new String((byte[]) o) + "]");
            } else {
              System.out.print(" [" + vv.getObject(i) + "]");
            }
//            break;
          }
          System.out.println();
        }
        loader.clear();
        b.release();
      }
      client.close();
      System.out.println(String.format("Got %d total results", count));
    }
  }
 
Example 6
Source File: DremioSeparatePlanningTest.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) {
  QueryData queryHeader = result.getHeader();
  int rows = queryHeader.getRowCount();
  try {
    if ( result.hasData() ) {
      ArrowBuf data = result.getData();
      loader.load(queryHeader.getDef(), data);
      for (int i = 0; i < rows; i++) {
         Map<String,String> record = Maps.newHashMap();
        for (VectorWrapper<?> vw : loader) {
          final String field = vw.getValueVector().getField().getName();
          final ValueVector vv = vw.getValueVector();
          final Object value = i < vv.getValueCount() ? vv.getObject(i) : null;
          final String display = value == null ? null : value.toString();
          record.put(field, display);
        }
        records.add(record);
      }
      loader.clear();
    }
    result.release();
  } catch (SchemaChangeException e) {
    fail(e.getMessage());
  }

}
 
Example 7
Source File: TestHashJoinAdvanced.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void multipleConditionJoin() throws Exception {

  // Function tests hash join with multiple join conditions
  final String plan = Files
      .toString(FileUtils.getResourceAsFile("/join/hj_multi_condition_join.json"), Charsets.UTF_8)
      .replace("#{TEST_FILE_1}", FileUtils.getResourceAsFile("/build_side_input.json").toURI().toString())
      .replace("#{TEST_FILE_2}", FileUtils.getResourceAsFile("/probe_side_input.json").toURI().toString());

  List<QueryDataBatch> results = testRunAndReturn(QueryType.PHYSICAL, plan);
  try (RecordBatchLoader batchLoader = new RecordBatchLoader(nodes[0].getContext().getAllocator())) {
    final QueryDataBatch batch = results.get(1);
    assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

    final Iterator<VectorWrapper<?>> itr = batchLoader.iterator();

    // Just test the join key
    final long colA[] = { 1, 2, 1 };
    final long colC[] = { 100, 200, 500 };

    // Check the output of decimal9
    final ValueVector intValueVector1 = itr.next().getValueVector();
    final ValueVector intValueVector2 = itr.next().getValueVector();

    for (int i = 0; i < intValueVector1.getValueCount(); i++) {
      assertEquals(intValueVector1.getObject(i), colA[i]);
      assertEquals(intValueVector2.getObject(i), colC[i]);
    }
    assertEquals(3, intValueVector1.getValueCount());
  }

  for (final QueryDataBatch result : results) {
    result.release();
  }

}
 
Example 8
Source File: TestHashJoinAdvanced.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void simpleEqualityJoin() throws Throwable {
  // Function checks hash join with single equality condition

  final String plan = Files.toString(FileUtils.getResourceAsFile("/join/hash_join.json"), Charsets.UTF_8)
                  .replace("#{TEST_FILE_1}", FileUtils.getResourceAsFile("/build_side_input.json").toURI().toString())
                  .replace("#{TEST_FILE_2}", FileUtils.getResourceAsFile("/probe_side_input.json").toURI().toString());

  List<QueryDataBatch> results = testRunAndReturn(QueryType.PHYSICAL, plan);
  try(RecordBatchLoader batchLoader = new RecordBatchLoader(nodes[0].getContext().getAllocator())){

    QueryDataBatch batch = results.get(1);
    assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

    Iterator<VectorWrapper<?>> itr = batchLoader.iterator();

    // Just test the join key
    long colA[] = {1, 1, 2, 2, 1, 1};

    // Check the output of decimal9
    ValueVector intValueVector = itr.next().getValueVector();


    for (int i = 0; i < intValueVector.getValueCount(); i++) {
      assertEquals(intValueVector.getObject(i), colA[i]);
    }
    assertEquals(6, intValueVector.getValueCount());
  }

  for (QueryDataBatch result : results) {
    result.release();
  }

}
 
Example 9
Source File: ArrowColumnFactory.java    From yosegi with Apache License 2.0 5 votes vote down vote up
/**
 * Convert Arrow's vector to IColumn.
 */
public static IColumn convert( final String name , final ValueVector vector ) {
  if ( vector.getNullCount() == vector.getValueCount() ) {
    return NullColumn.getInstance();
  }

  ColumnFactory factory = dispatch.get( vector.getClass() );
  if ( factory == null ) {
    throw new UnsupportedOperationException(
        "Unsupported vector : " + vector.getClass().getName() );
  }
  return factory.get( name , vector );
}
 
Example 10
Source File: TestMergingReceiver.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultipleProvidersMixedSizes() throws Exception {
  try (final ClusterCoordinator clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
       final SabotNode bit1 = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT, true);
       final SabotNode bit2 = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT, false);
       final DremioClient client = new DremioClient(DEFAULT_SABOT_CONFIG, clusterCoordinator);) {

    bit1.run();
    bit2.run();
    client.connect();
    final List<QueryDataBatch> results =
        client.runQuery(com.dremio.exec.proto.UserBitShared.QueryType.PHYSICAL,
            Files.toString(FileUtils.getResourceAsFile("/mergerecv/multiple_providers.json"),
                Charsets.UTF_8));
    int count = 0;
    final RecordBatchLoader batchLoader = new RecordBatchLoader(client.getRecordAllocator());
    // print the results
    Long lastBlueValue = null;
    for (final QueryDataBatch b : results) {
      final QueryData queryData = b.getHeader();
      final int batchRowCount = queryData.getRowCount();
      count += batchRowCount;
      batchLoader.load(queryData.getDef(), b.getData());
      for (final VectorWrapper vw : batchLoader) {
        final ValueVector vv = vw.getValueVector();
        final Field materializedField = vv.getField();
        final int numValues = vv.getValueCount();
        for(int valueIdx = 0; valueIdx < numValues; ++valueIdx) {
          if (materializedField.getName().equals("blue")) {
            Long val = (Long) vv.getObject(valueIdx);
            if (val != null) {
              final long longValue = ((Long) vv.getObject(valueIdx)).longValue();
              // check that order is ascending
              if (lastBlueValue != null) {
                assertTrue(longValue >= lastBlueValue);
              }
              lastBlueValue = longValue;
            }
          }
        }
      }
      b.release();
      batchLoader.clear();
    }
    assertEquals(400000, count);
  }
}
 
Example 11
Source File: TestDecimal.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Test
public void testComplexDecimalSort() throws Exception {

    // Function checks if sort output on complex decimal type works
    try (ClusterCoordinator clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
         SabotNode bit = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT, true);
         DremioClient client = new DremioClient(DEFAULT_SABOT_CONFIG, clusterCoordinator)) {

        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(com.dremio.exec.proto.UserBitShared.QueryType.PHYSICAL,
                Files.toString(FileUtils.getResourceAsFile("/decimal/test_decimal_sort_complex.json"), Charsets.UTF_8)
                        .replace("#{TEST_FILE}", "/input_sort_complex_decimal.json")
        );

        RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());

        QueryDataBatch batch = results.get(1);
        assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

        String sortOutput[] = {"-100000000001.000000000000",
                               "-100000000001.000000000000",
                               "-145456789.120123000000",
                               "-0.120000000000",
                               "0.100000000001",
                               "11.123456789012",
                               "1278789.100000000000",
                               "145456789.120123000000",
                               "100000000001.123456789001",
                               "123456789123456789.000000000000"};

        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();

        // Check the output of sort
        VectorWrapper<?> v = itr.next();
        ValueVector vv = v.getValueVector();

        for (int i = 0; i < vv.getValueCount(); i++) {
            assertEquals(sortOutput[i], vv.getObject(i).toString());
        }
        assertEquals(10, vv.getValueCount());

        batchLoader.clear();
        for (QueryDataBatch result : results) {
          result.release();
        }
    }
}
 
Example 12
Source File: TestDecimal.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Test
@Ignore("decimal")
public void testComplexDecimal() throws Exception {

    /* Function checks casting between varchar and decimal38sparse
     * Also checks arithmetic on decimal38sparse
     */
    try (ClusterCoordinator clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
         SabotNode bit = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT, true);
         DremioClient client = new DremioClient(DEFAULT_SABOT_CONFIG, clusterCoordinator)) {

        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(com.dremio.exec.proto.UserBitShared.QueryType.PHYSICAL,
                Files.toString(FileUtils.getResourceAsFile("/decimal/test_decimal_complex.json"), Charsets.UTF_8)
                        .replace("#{TEST_FILE}", "/input_complex_decimal.json")
        );

        RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());

        QueryDataBatch batch = results.get(0);
        assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

        String addOutput[] = {"-99999998877.700000000", "11.423456789", "123456789.100000000", "-0.119998000", "100000000112.423456789" , "-99999999879.907000000", "123456789123456801.300000000"};
        String subtractOutput[] = {"-100000001124.300000000", "10.823456789", "-123456788.900000000", "-0.120002000", "99999999889.823456789", "-100000000122.093000000", "123456789123456776.700000000"};

        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();

        ValueVector addValueVector = itr.next().getValueVector();
        ValueVector subValueVector = itr.next().getValueVector();

        for (int i = 0; i < addValueVector.getValueCount(); i++) {
            assertEquals(addValueVector.getObject(i).toString(), addOutput[i]);
            assertEquals(subValueVector.getObject(i).toString(), subtractOutput[i]);
        }
        assertEquals(7, addValueVector.getValueCount());
        assertEquals(7, subValueVector.getValueCount());

        batchLoader.clear();
        for (QueryDataBatch result : results) {
          result.release();
        }
    }
}
 
Example 13
Source File: TestDecimal.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Test
@Ignore("decimal")
public void testSimpleDecimalArithmetic() throws Exception {

    // Function checks arithmetic operations on Decimal18
    try (ClusterCoordinator clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
         SabotNode bit = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT, true);
         DremioClient client = new DremioClient(DEFAULT_SABOT_CONFIG, clusterCoordinator)) {

        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(com.dremio.exec.proto.UserBitShared.QueryType.PHYSICAL,
                Files.toString(FileUtils.getResourceAsFile("/decimal/simple_decimal_arithmetic.json"), Charsets.UTF_8)
                        .replace("#{TEST_FILE}", "/input_simple_decimal.json")
        );

        RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());

        QueryDataBatch batch = results.get(0);
        assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

        String addOutput[] = {"123456888.0", "22.2", "0.2", "-0.2", "-987654444.2","-3.0"};
        String subtractOutput[] = {"123456690.0", "0.0", "0.0", "0.0", "-987654198.0", "-1.0"};
        String multiplyOutput[] = {"12222222111.00" , "123.21" , "0.01", "0.01",  "121580246927.41", "2.00"};

        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();

        // Check the output of add
        ValueVector addValueVector = itr.next().getValueVector();
        ValueVector subValueVector = itr.next().getValueVector();
        ValueVector mulValueVector = itr.next().getValueVector();

        for (int i = 0; i < addValueVector.getValueCount(); i++) {
            assertEquals(addValueVector.getObject(i).toString(), addOutput[i]);
            assertEquals(subValueVector.getObject(i).toString(), subtractOutput[i]);
            assertEquals(mulValueVector.getObject(i).toString(), multiplyOutput[i]);

        }
        assertEquals(6, addValueVector.getValueCount());
        assertEquals(6, subValueVector.getValueCount());
        assertEquals(6, mulValueVector.getValueCount());

        batchLoader.clear();
        for (QueryDataBatch result : results) {
          result.release();
        }
    }
}
 
Example 14
Source File: TestDecimal.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Test
public void testCastFromFloat() throws Exception {

    // Function checks for casting from Float, Double to Decimal data types
    try (ClusterCoordinator clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
         SabotNode bit = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT, true);
         DremioClient client = new DremioClient(DEFAULT_SABOT_CONFIG, clusterCoordinator)) {

        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(com.dremio.exec.proto.UserBitShared.QueryType.PHYSICAL,
                Files.toString(FileUtils.getResourceAsFile("/decimal/cast_float_decimal.json"), Charsets.UTF_8)
                        .replace("#{TEST_FILE}", "/input_simple_decimal.json")
        );

        RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());

        QueryDataBatch batch = results.get(0);
        assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

        String decimal9Output[] = {"99.0000", "11.1235", "0.1000", "-0.1200", "-123.1234", "-1.0001"};
        String decimal38Output[] = {"123456789.0000", "11.1235", "0.1000", "-0.1004", "-987654321.1235", "-2.0301"};

        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();

        // Check the output of decimal9
        ValueVector dec9ValueVector = itr.next().getValueVector();
        ValueVector dec38ValueVector = itr.next().getValueVector();


        for (int i = 0; i < dec9ValueVector.getValueCount(); i++) {
            assertEquals(dec9ValueVector.getObject(i).toString(), decimal9Output[i]);
            assertEquals(dec38ValueVector.getObject(i).toString(), decimal38Output[i]);
        }
        assertEquals(6, dec9ValueVector.getValueCount());
        assertEquals(6, dec38ValueVector.getValueCount());

        batchLoader.clear();
        for (QueryDataBatch result : results) {
          result.release();
        }
    }
}
 
Example 15
Source File: ParquetResultListener.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
synchronized public void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) {
  logger.debug("result arrived in test batch listener.");
  int columnValCounter = 0;
  FieldInfo currentField;
  count += result.getHeader().getRowCount();
  boolean schemaChanged = false;
  final RecordBatchLoader batchLoader = new RecordBatchLoader(allocator);
  try {
    schemaChanged = batchLoader.load(result.getHeader().getDef(), result.getData());
    // TODO:  Clean:  DRILL-2933:  That load(...) no longer throws
    // SchemaChangeException, so check/clean catch clause below.
  } catch (SchemaChangeException e) {
    throw new RuntimeException(e);
  }

  // used to make sure each vector in the batch has the same number of records
  int valueCount = batchLoader.getRecordCount();

  // print headers.
  if (schemaChanged) {
  } // do not believe any change is needed for when the schema changes, with the current mock scan use case

  for (final VectorWrapper vw : batchLoader) {
    final ValueVector vv = vw.getValueVector();
    currentField = props.fields.get(vv.getField().getName());
    if (!valuesChecked.containsKey(vv.getField().getName())) {
      valuesChecked.put(vv.getField().getName(), 0);
      columnValCounter = 0;
    } else {
      columnValCounter = valuesChecked.get(vv.getField().getName());
    }
    printColumnMajor(vv);

    if (testValues) {
      for (int j = 0; j < vv.getValueCount(); j++) {
        assertField(vv, j, currentField.type,
            currentField.values[columnValCounter % 3], currentField.name + "/");
        columnValCounter++;
      }
    } else {
      columnValCounter += vv.getValueCount();
    }

    valuesChecked.remove(vv.getField().getName());
    assertEquals("Mismatched value count for vectors in the same batch.", valueCount, vv.getValueCount());
    valuesChecked.put(vv.getField().getName(), columnValCounter);
  }

  if (ParquetRecordReaderTest.VERBOSE_DEBUG){
    printRowMajor(batchLoader);
  }
  batchCounter++;

  batchLoader.clear();
  result.release();
}
 
Example 16
Source File: TestDecimal.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleDecimal() throws Exception {

    /* Function checks casting from VarChar to Decimal9, Decimal18 and vice versa
     * Also tests instances where the scale might have to truncated when scale provided < input fraction
     */
    try (ClusterCoordinator clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
         SabotNode bit = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT, true);
         DremioClient client = new DremioClient(DEFAULT_SABOT_CONFIG, clusterCoordinator)) {

        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(com.dremio.exec.proto.UserBitShared.QueryType.PHYSICAL,
                Files.toString(FileUtils.getResourceAsFile("/decimal/cast_simple_decimal.json"), Charsets.UTF_8)
                        .replace("#{TEST_FILE}", "/input_simple_decimal.json")
        );

        RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());

        QueryDataBatch batch = results.get(0);
        assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

        String decimal9Output[] = {"99.0000", "11.1235", "0.1000", "-0.1200", "-123.1234", "-1.0001"};
        String decimal18Output[] = {"123456789.000000000", "11.123456789", "0.100000000", "-0.100400000", "-987654321.123456789", "-2.030100000"};

        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();

        // Check the output of decimal9
        ValueVector dec9ValueVector = itr.next().getValueVector();
        ValueVector dec18ValueVector = itr.next().getValueVector();


        for (int i = 0; i < dec9ValueVector.getValueCount(); i++) {
            assertEquals(dec9ValueVector.getObject(i).toString(), decimal9Output[i]);
            assertEquals(dec18ValueVector.getObject(i).toString(), decimal18Output[i]);
        }
        assertEquals(6, dec9ValueVector.getValueCount());
        assertEquals(6, dec18ValueVector.getValueCount());

        batchLoader.clear();
        for (QueryDataBatch result : results) {
          result.release();
        }
    }
}
 
Example 17
Source File: HyperVectorValueIterator.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public void determineTotalSize() {
  for (ValueVector vv : hyperVector.getValueVectors()) {
    this.totalValues += vv.getValueCount();
  }
}