Search in sources :

Example 16 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by apache.

the class TestUnnestWithLateralCorrectness method testNestedUnnest.

/**
 *     Run a plan like the following for various input batches :
 *             Lateral1
 *               /    \
 *              /    Lateral2
 *            Scan      / \
 *                     /   \
 *                Project1 Project2
 *                   /       \
 *                  /         \
 *              Unnest1      Unnest2
 *
 * @param incomingSchemas
 * @param iterOutcomes
 * @param execKill
 * @param data
 * @param baseline
 * @param <T>
 * @throws Exception
 */
private <T> void testNestedUnnest(TupleMetadata[] incomingSchemas, RecordBatch.IterOutcome[] iterOutcomes, // number of batches after which to kill the execution (!)
int execKill, T[][] data, T[][][] baseline) throws Exception {
    // Get the incoming container with dummy data for LJ
    final List<VectorContainer> incomingContainer = new ArrayList<>(data.length);
    // Create data
    ArrayList<RowSet.SingleRowSet> rowSets = new ArrayList<>();
    int rowNumber = 0;
    int batchNum = 0;
    for (Object[] recordBatch : data) {
        RowSetBuilder rowSetBuilder = fixture.rowSetBuilder(incomingSchemas[batchNum]);
        for (Object rowData : recordBatch) {
            rowSetBuilder.addRow(++rowNumber, rowData);
        }
        RowSet.SingleRowSet rowSet = rowSetBuilder.build();
        rowSets.add(rowSet);
        incomingContainer.add(rowSet.container());
        batchNum++;
    }
    // Get the unnest POPConfig
    final UnnestPOP unnestPopConfig1 = new UnnestPOP(null, SchemaPath.getSimplePath("unnestColumn"), DrillUnnestRelBase.IMPLICIT_COLUMN);
    final UnnestPOP unnestPopConfig2 = new UnnestPOP(null, SchemaPath.getSimplePath("colB"), DrillUnnestRelBase.IMPLICIT_COLUMN);
    // Get the IterOutcomes for LJ
    final List<RecordBatch.IterOutcome> outcomes = new ArrayList<>(iterOutcomes.length);
    for (RecordBatch.IterOutcome o : iterOutcomes) {
        outcomes.add(o);
    }
    // Create incoming MockRecordBatch
    final MockRecordBatch incomingMockBatch = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, incomingContainer, outcomes, incomingContainer.get(0).getSchema());
    // setup Unnest record batch
    final UnnestRecordBatch unnestBatch1 = new UnnestRecordBatch(unnestPopConfig1, fixture.getFragmentContext());
    final UnnestRecordBatch unnestBatch2 = new UnnestRecordBatch(unnestPopConfig2, fixture.getFragmentContext());
    // Create intermediate Project
    final Project projectPopConfig1 = new Project(DrillLogicalTestUtils.parseExprs("unnestColumn.colB", "colB", unnestPopConfig1.getImplicitColumn(), unnestPopConfig1.getImplicitColumn()), unnestPopConfig1);
    final ProjectRecordBatch projectBatch1 = new ProjectRecordBatch(projectPopConfig1, unnestBatch1, fixture.getFragmentContext());
    final Project projectPopConfig2 = new Project(DrillLogicalTestUtils.parseExprs("colB", "unnestColumn2", unnestPopConfig2.getImplicitColumn(), unnestPopConfig2.getImplicitColumn()), unnestPopConfig2);
    final ProjectRecordBatch projectBatch2 = new ProjectRecordBatch(projectPopConfig2, unnestBatch2, fixture.getFragmentContext());
    final LateralJoinPOP ljPopConfig2 = new LateralJoinPOP(projectPopConfig1, projectPopConfig2, JoinRelType.INNER, DrillLateralJoinRelBase.IMPLICIT_COLUMN, Lists.newArrayList());
    final LateralJoinPOP ljPopConfig1 = new LateralJoinPOP(mockPopConfig, ljPopConfig2, JoinRelType.INNER, DrillLateralJoinRelBase.IMPLICIT_COLUMN, Lists.newArrayList());
    final LateralJoinBatch lateralJoinBatch2 = new LateralJoinBatch(ljPopConfig2, fixture.getFragmentContext(), projectBatch1, projectBatch2);
    final LateralJoinBatch lateralJoinBatch1 = new LateralJoinBatch(ljPopConfig1, fixture.getFragmentContext(), incomingMockBatch, lateralJoinBatch2);
    // set pointer to Lateral in unnest
    unnestBatch1.setIncoming((LateralContract) lateralJoinBatch1);
    unnestBatch2.setIncoming((LateralContract) lateralJoinBatch2);
    // Simulate the pipeline by calling next on the incoming
    // results is an array ot batches, each batch being an array of output vectors.
    List<List<ValueVector>> resultList = new ArrayList<>();
    List<List<ValueVector>> results = null;
    int batchesProcessed = 0;
    try {
        try {
            while (!isTerminal(lateralJoinBatch1.next())) {
                if (lateralJoinBatch1.getRecordCount() > 0) {
                    addBatchToResults(resultList, lateralJoinBatch1);
                }
                batchesProcessed++;
                if (batchesProcessed == execKill) {
                    lateralJoinBatch1.getContext().getExecutorState().fail(new DrillException("Testing failure of execution."));
                    lateralJoinBatch1.cancel();
                }
            // else nothing to do
            }
        } catch (UserException e) {
            throw e;
        } catch (Exception e) {
            throw new Exception("Test failed to execute lateralJoinBatch.next() because: " + e.getMessage());
        }
        // Check results against baseline
        results = resultList;
        int batchIndex = 0;
        int vectorIndex = 0;
        // int valueIndex = 0;
        for (List<ValueVector> batch : results) {
            int vectorCount = batch.size();
            if (vectorCount != baseline[batchIndex].length + 2) {
                // baseline does not include the original unnest column(s)
                fail("Test failed in validating unnest output. Batch column count mismatch.");
            }
            for (ValueVector vv : batch) {
                if (vv.getField().getName().equals("unnestColumn") || vv.getField().getName().equals("colB")) {
                    // skip the original input column
                    continue;
                }
                int valueCount = vv.getAccessor().getValueCount();
                if (valueCount != baseline[batchIndex][vectorIndex].length) {
                    fail("Test failed in validating unnest output. Value count mismatch in batch number " + (batchIndex + 1) + "" + ".");
                }
                for (int valueIndex = 0; valueIndex < valueCount; valueIndex++) {
                    if (vv instanceof MapVector) {
                        if (!compareMapBaseline(baseline[batchIndex][vectorIndex][valueIndex], vv.getAccessor().getObject(valueIndex))) {
                            fail("Test failed in validating unnest(Map) output. Value mismatch");
                        }
                    } else if (vv instanceof VarCharVector) {
                        Object val = vv.getAccessor().getObject(valueIndex);
                        if (((String) baseline[batchIndex][vectorIndex][valueIndex]).compareTo(val.toString()) != 0) {
                            fail("Test failed in validating unnest output. Value mismatch. Baseline value[]" + vectorIndex + "][" + valueIndex + "]" + ": " + baseline[vectorIndex][valueIndex] + "   VV.getObject(valueIndex): " + val);
                        }
                    } else {
                        Object val = vv.getAccessor().getObject(valueIndex);
                        if (!baseline[batchIndex][vectorIndex][valueIndex].equals(val)) {
                            fail("Test failed in validating unnest output. Value mismatch. Baseline value[" + vectorIndex + "][" + valueIndex + "]" + ": " + baseline[batchIndex][vectorIndex][valueIndex] + "   VV.getObject(valueIndex): " + val);
                        }
                    }
                }
                vectorIndex++;
            }
            vectorIndex = 0;
            batchIndex++;
        }
    } catch (UserException e) {
        // Valid exception
        throw e;
    } catch (Exception e) {
        fail("Test failed. Exception : " + e.getMessage());
    } finally {
        // Close all the resources for this test case
        unnestBatch1.close();
        lateralJoinBatch1.close();
        unnestBatch2.close();
        lateralJoinBatch2.close();
        incomingMockBatch.close();
        if (results != null) {
            for (List<ValueVector> batch : results) {
                for (ValueVector vv : batch) {
                    vv.clear();
                }
            }
        }
        for (RowSet.SingleRowSet rowSet : rowSets) {
            rowSet.clear();
        }
    }
}
Also used : MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) ProjectRecordBatch(org.apache.drill.exec.physical.impl.project.ProjectRecordBatch) RecordBatch(org.apache.drill.exec.record.RecordBatch) ArrayList(java.util.ArrayList) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) UnnestPOP(org.apache.drill.exec.physical.config.UnnestPOP) DrillException(org.apache.drill.common.exceptions.DrillException) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) ArrayList(java.util.ArrayList) List(java.util.List) UserException(org.apache.drill.common.exceptions.UserException) LateralJoinBatch(org.apache.drill.exec.physical.impl.join.LateralJoinBatch) VarCharVector(org.apache.drill.exec.vector.VarCharVector) UserException(org.apache.drill.common.exceptions.UserException) DrillException(org.apache.drill.common.exceptions.DrillException) VectorContainer(org.apache.drill.exec.record.VectorContainer) ValueVector(org.apache.drill.exec.vector.ValueVector) Project(org.apache.drill.exec.physical.config.Project) LateralJoinPOP(org.apache.drill.exec.physical.config.LateralJoinPOP) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) ProjectRecordBatch(org.apache.drill.exec.physical.impl.project.ProjectRecordBatch) MapVector(org.apache.drill.exec.vector.complex.MapVector)

Example 17 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.

the class SSLConfig method initializeKeyManagerFactory.

public KeyManagerFactory initializeKeyManagerFactory() throws DrillException {
    KeyManagerFactory kmf;
    String keyStorePath = getKeyStorePath();
    String keyStorePassword = getKeyStorePassword();
    String keyStoreType = getKeyStoreType();
    try {
        if (keyStorePath.isEmpty()) {
            throw new DrillException("No Keystore provided.");
        }
        KeyStore ks = KeyStore.getInstance(!keyStoreType.isEmpty() ? keyStoreType : KeyStore.getDefaultType());
        // initialize the key manager factory
        // Will throw an exception if the file is not found/accessible.
        InputStream ksStream = new FileInputStream(keyStorePath);
        // A key password CANNOT be null or an empty string.
        if (keyStorePassword.isEmpty()) {
            throw new DrillException("The Keystore password cannot be empty.");
        }
        ks.load(ksStream, keyStorePassword.toCharArray());
        // Empty Keystore. (Remarkably, it is possible to do this).
        if (ks.size() == 0) {
            throw new DrillException("The Keystore has no entries.");
        }
        kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, getKeyPassword().toCharArray());
    } catch (Exception e) {
        throw new DrillException(new StringBuilder().append("Exception while initializing the keystore: [").append(e.getMessage()).append("]. ").toString());
    }
    return kmf;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DrillException(org.apache.drill.common.exceptions.DrillException) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) DrillException(org.apache.drill.common.exceptions.DrillException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 18 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.

the class SSLConfigClient method initNettySslContext.

@Override
public SslContext initNettySslContext() throws DrillException {
    final SslContext sslCtx;
    if (!userSslEnabled) {
        return null;
    }
    TrustManagerFactory tmf;
    try {
        tmf = initializeTrustManagerFactory();
        sslCtx = SslContextBuilder.forClient().sslProvider(getProvider()).trustManager(tmf).protocols(protocol).build();
    } catch (Exception e) {
        // Catch any SSL initialization Exceptions here and abort.
        throw new DrillException(new StringBuilder().append("SSL is enabled but cannot be initialized due to the following exception: ").append("[ ").append(e.getMessage()).append("]. ").toString());
    }
    this.nettySslContext = sslCtx;
    return sslCtx;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException) SslContext(io.netty.handler.ssl.SslContext)

Example 19 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.

the class SSLConfigServer method initNettySslContext.

@Override
public SslContext initNettySslContext() throws DrillException {
    final SslContext sslCtx;
    if (!userSslEnabled) {
        return null;
    }
    KeyManagerFactory kmf;
    TrustManagerFactory tmf;
    try {
        if (keyStorePath.isEmpty()) {
            throw new DrillException("No Keystore provided.");
        }
        kmf = initializeKeyManagerFactory();
        tmf = initializeTrustManagerFactory();
        sslCtx = SslContextBuilder.forServer(kmf).trustManager(tmf).protocols(protocol).sslProvider(getProvider()).build();
    } catch (Exception e) {
        // Catch any SSL initialization Exceptions here and abort.
        throw new DrillException(new StringBuilder().append("SSL is enabled but cannot be initialized - ").append("[ ").append(e.getMessage()).append("]. ").toString());
    }
    this.nettySslContext = sslCtx;
    return sslCtx;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException) SslContext(io.netty.handler.ssl.SslContext) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 20 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.

the class TestSpnegoConfig method testSpnegoConfigOnlyKeytab.

/**
 * Invalid configuration with keytab only and missing principal
 * @throws Exception
 */
@Test
public void testSpnegoConfigOnlyKeytab() throws Exception {
    try {
        final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))).withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())).withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)));
        final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig);
        spnegoConfig.validateSpnegoConfig();
        fail();
    } catch (Exception ex) {
        assertTrue(ex instanceof DrillException);
    }
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) SpnegoConfig(org.apache.drill.exec.server.rest.auth.SpnegoConfig) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException) Test(org.junit.Test) SecurityTest(org.apache.drill.categories.SecurityTest)

Aggregations

DrillException (org.apache.drill.common.exceptions.DrillException)28 SecurityTest (org.apache.drill.categories.SecurityTest)12 Test (org.junit.Test)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)10 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)6 DrillConfig (org.apache.drill.common.config.DrillConfig)6 SpnegoConfig (org.apache.drill.exec.server.rest.auth.SpnegoConfig)6 SSLConfig (org.apache.drill.exec.ssl.SSLConfig)6 SSLConfigBuilder (org.apache.drill.exec.ssl.SSLConfigBuilder)6 BaseTest (org.apache.drill.test.BaseTest)6 ConfigBuilder (org.apache.drill.test.ConfigBuilder)6 SslContext (io.netty.handler.ssl.SslContext)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 KeyStore (java.security.KeyStore)4 SSLContext (javax.net.ssl.SSLContext)4 Configuration (org.apache.hadoop.conf.Configuration)4 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2