Search in sources :

Example 26 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.

the class TestInfoSchema method describeSchemaOutput.

@Test
public void describeSchemaOutput() throws Exception {
    final List<QueryDataBatch> result = testSqlWithResults("describe schema dfs_test.tmp");
    assertTrue(result.size() == 1);
    final QueryDataBatch batch = result.get(0);
    final RecordBatchLoader loader = new RecordBatchLoader(getDrillbitContext().getAllocator());
    loader.load(batch.getHeader().getDef(), batch.getData());
    // check schema column value
    final VectorWrapper schemaValueVector = loader.getValueAccessorById(NullableVarCharVector.class, loader.getValueVectorId(SchemaPath.getCompoundPath("schema")).getFieldIds());
    String schema = schemaValueVector.getValueVector().getAccessor().getObject(0).toString();
    assertEquals("dfs_test.tmp", schema);
    // check properties column value
    final VectorWrapper propertiesValueVector = loader.getValueAccessorById(NullableVarCharVector.class, loader.getValueVectorId(SchemaPath.getCompoundPath("properties")).getFieldIds());
    String properties = propertiesValueVector.getValueVector().getAccessor().getObject(0).toString();
    final Map configMap = mapper.readValue(properties, Map.class);
    // check some stable properties existence
    assertTrue(configMap.containsKey("connection"));
    assertTrue(configMap.containsKey("config"));
    assertTrue(configMap.containsKey("formats"));
    assertFalse(configMap.containsKey("workspaces"));
    // check some stable properties values
    assertEquals("file", configMap.get("type"));
    final FileSystemConfig testConfig = (FileSystemConfig) bits[0].getContext().getStorage().getPlugin("dfs_test").getConfig();
    final String tmpSchemaLocation = testConfig.workspaces.get("tmp").getLocation();
    assertEquals(tmpSchemaLocation, configMap.get("location"));
    batch.release();
    loader.clear();
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig) Map(java.util.Map) Test(org.junit.Test)

Example 27 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.

the class TestDecimal method testCastFromFloat.

@Test
public void testCastFromFloat() throws Exception {
    // Function checks for casting from Float, Double to Decimal data types
    try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
        Drillbit bit = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(org.apache.drill.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.Accessor dec9Accessor = itr.next().getValueVector().getAccessor();
        ValueVector.Accessor dec38Accessor = itr.next().getValueVector().getAccessor();
        for (int i = 0; i < dec9Accessor.getValueCount(); i++) {
            assertEquals(dec9Accessor.getObject(i).toString(), decimal9Output[i]);
            assertEquals(dec38Accessor.getObject(i).toString(), decimal38Output[i]);
        }
        assertEquals(6, dec9Accessor.getValueCount());
        assertEquals(6, dec38Accessor.getValueCount());
        batchLoader.clear();
        for (QueryDataBatch result : results) {
            result.release();
        }
    }
}
Also used : RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Example 28 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.

the class TestDecimal method testComplexDecimal.

@Test
public void testComplexDecimal() throws Exception {
    /* Function checks casting between varchar and decimal38sparse
         * Also checks arithmetic on decimal38sparse
         */
    try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
        Drillbit bit = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(org.apache.drill.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.Accessor addAccessor = itr.next().getValueVector().getAccessor();
        ValueVector.Accessor subAccessor = itr.next().getValueVector().getAccessor();
        for (int i = 0; i < addAccessor.getValueCount(); i++) {
            assertEquals(addAccessor.getObject(i).toString(), addOutput[i]);
            assertEquals(subAccessor.getObject(i).toString(), subtractOutput[i]);
        }
        assertEquals(7, addAccessor.getValueCount());
        assertEquals(7, subAccessor.getValueCount());
        batchLoader.clear();
        for (QueryDataBatch result : results) {
            result.release();
        }
    }
}
Also used : RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Example 29 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.

the class TestDecimal method testComplexDecimalSort.

@Test
public void testComplexDecimalSort() throws Exception {
    // Function checks if sort output on complex decimal type works
    try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
        Drillbit bit = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(org.apache.drill.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.Accessor accessor = v.getValueVector().getAccessor();
        for (int i = 0; i < accessor.getValueCount(); i++) {
            assertEquals(sortOutput[i], accessor.getObject(i).toString());
        }
        assertEquals(10, accessor.getValueCount());
        batchLoader.clear();
        for (QueryDataBatch result : results) {
            result.release();
        }
    }
}
Also used : RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Example 30 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.

the class TestDecimal method testSimpleDecimalArithmetic.

@Test
public void testSimpleDecimalArithmetic() throws Exception {
    // Function checks arithmetic operations on Decimal18
    try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
        Drillbit bit = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        // run query.
        bit.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(org.apache.drill.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.Accessor addAccessor = itr.next().getValueVector().getAccessor();
        ValueVector.Accessor subAccessor = itr.next().getValueVector().getAccessor();
        ValueVector.Accessor mulAccessor = itr.next().getValueVector().getAccessor();
        for (int i = 0; i < addAccessor.getValueCount(); i++) {
            assertEquals(addAccessor.getObject(i).toString(), addOutput[i]);
            assertEquals(subAccessor.getObject(i).toString(), subtractOutput[i]);
            assertEquals(mulAccessor.getObject(i).toString(), multiplyOutput[i]);
        }
        assertEquals(6, addAccessor.getValueCount());
        assertEquals(6, subAccessor.getValueCount());
        assertEquals(6, mulAccessor.getValueCount());
        batchLoader.clear();
        for (QueryDataBatch result : results) {
            result.release();
        }
    }
}
Also used : RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Aggregations

VectorWrapper (org.apache.drill.exec.record.VectorWrapper)36 ValueVector (org.apache.drill.exec.vector.ValueVector)23 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)17 Test (org.junit.Test)17 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)16 DrillClient (org.apache.drill.exec.client.DrillClient)13 Drillbit (org.apache.drill.exec.server.Drillbit)13 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)13 ExecTest (org.apache.drill.exec.ExecTest)4 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)4 Stopwatch (com.google.common.base.Stopwatch)3 IOException (java.io.IOException)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 ClassTransformationException (org.apache.drill.exec.exception.ClassTransformationException)3 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)3 VectorContainer (org.apache.drill.exec.record.VectorContainer)3 VarBinaryHolder (org.apache.drill.exec.expr.holders.VarBinaryHolder)2 RecordBatchData (org.apache.drill.exec.physical.impl.sort.RecordBatchData)2 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)2