Search in sources :

Example 31 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class TestHelper method getConfigurations.

public static AsterixConfiguration getConfigurations(String fileName) throws IOException, JAXBException, AsterixException {
    try (InputStream is = TestHelper.class.getClassLoader().getResourceAsStream(fileName)) {
        if (is != null) {
            JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
            Unmarshaller unmarshaller = ctx.createUnmarshaller();
            return (AsterixConfiguration) unmarshaller.unmarshal(is);
        } else {
            throw new AsterixException("Could not find configuration file " + fileName);
        }
    }
}
Also used : AsterixException(org.apache.asterix.common.exceptions.AsterixException) AsterixConfiguration(org.apache.asterix.common.configuration.AsterixConfiguration) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 32 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class DmlTest method enlistTest.

@Test
public void enlistTest() throws Exception {
    File outdir = new File(PATH_ACTUAL);
    if (outdir.exists()) {
        AsterixTestHelper.deleteRec(outdir);
    }
    outdir.mkdirs();
    integrationUtil.init(true);
    Reader loadReader = new BufferedReader(new InputStreamReader(new FileInputStream(LOAD_FOR_ENLIST_FILE), "UTF-8"));
    AsterixJavaClient asterixLoad = new AsterixJavaClient((ICcApplicationContext) integrationUtil.cc.getApplicationContext(), integrationUtil.getHyracksClientConnection(), loadReader, ERR, new AqlCompilationProvider(), new DefaultStatementExecutorFactory(), new StorageComponentProvider());
    try {
        asterixLoad.compile(true, false, false, false, false, true, false);
    } catch (AsterixException e) {
        throw new Exception("Compile ERROR for " + LOAD_FOR_ENLIST_FILE + ": " + e.getMessage(), e);
    } finally {
        loadReader.close();
    }
    asterixLoad.execute();
    integrationUtil.deinit(true);
    for (String d : ASTERIX_DATA_DIRS) {
        testExecutor.deleteRec(new File(d));
    }
    outdir.delete();
}
Also used : AqlCompilationProvider(org.apache.asterix.compiler.provider.AqlCompilationProvider) AsterixException(org.apache.asterix.common.exceptions.AsterixException) InputStreamReader(java.io.InputStreamReader) DefaultStatementExecutorFactory(org.apache.asterix.app.translator.DefaultStatementExecutorFactory) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) StorageComponentProvider(org.apache.asterix.file.StorageComponentProvider) File(java.io.File) AsterixJavaClient(org.apache.asterix.api.java.AsterixJavaClient) FileInputStream(java.io.FileInputStream) AsterixException(org.apache.asterix.common.exceptions.AsterixException) Test(org.junit.Test)

Example 33 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class OptimizerTest method test.

@Test
public void test() throws Exception {
    try {
        String queryFileShort = queryFile.getPath().substring(PATH_QUERIES.length()).replace(SEPARATOR.charAt(0), '/');
        if (!only.isEmpty()) {
            boolean toRun = TestHelper.isInPrefixList(only, queryFileShort);
            if (!toRun) {
                LOGGER.info("SKIP TEST: \"" + queryFile.getPath() + "\" \"only.txt\" not empty and not in \"only.txt\".");
            }
            Assume.assumeTrue(toRun);
        }
        boolean skipped = TestHelper.isInPrefixList(ignore, queryFileShort);
        if (skipped) {
            LOGGER.info("SKIP TEST: \"" + queryFile.getPath() + "\" in \"ignore.txt\".");
        }
        Assume.assumeTrue(!skipped);
        LOGGER.info("RUN TEST: \"" + queryFile.getPath() + "\"");
        Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFile), "UTF-8"));
        // Forces the creation of actualFile.
        actualFile.getParentFile().mkdirs();
        PrintWriter plan = new PrintWriter(actualFile);
        ILangCompilationProvider provider = queryFile.getName().endsWith("aql") ? aqlCompilationProvider : sqlppCompilationProvider;
        if (extensionLangCompilationProvider != null) {
            provider = extensionLangCompilationProvider;
        }
        IHyracksClientConnection hcc = integrationUtil.getHyracksClientConnection();
        AsterixJavaClient asterix = new AsterixJavaClient((ICcApplicationContext) integrationUtil.cc.getApplicationContext(), hcc, query, plan, provider, statementExecutorFactory, storageComponentProvider);
        try {
            asterix.compile(true, false, false, true, true, false, false);
        } catch (AsterixException e) {
            plan.close();
            query.close();
            throw new Exception("Compile ERROR for " + queryFile + ": " + e.getMessage(), e);
        }
        plan.close();
        query.close();
        BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile), "UTF-8"));
        BufferedReader readerActual = new BufferedReader(new InputStreamReader(new FileInputStream(actualFile), "UTF-8"));
        String lineExpected, lineActual;
        int num = 1;
        try {
            while ((lineExpected = readerExpected.readLine()) != null) {
                lineActual = readerActual.readLine();
                if (lineActual == null) {
                    throw new Exception("Result for " + queryFile + " changed at line " + num + ":\n< " + lineExpected + "\n> ");
                }
                if (!lineExpected.equals(lineActual)) {
                    throw new Exception("Result for " + queryFile + " changed at line " + num + ":\n< " + lineExpected + "\n> " + lineActual);
                }
                ++num;
            }
            lineActual = readerActual.readLine();
            if (lineActual != null) {
                throw new Exception("Result for " + queryFile + " changed at line " + num + ":\n< \n> " + lineActual);
            }
            LOGGER.info("Test \"" + queryFile.getPath() + "\" PASSED!");
            actualFile.delete();
        } finally {
            readerExpected.close();
            readerActual.close();
        }
    } catch (Exception e) {
        if (!(e instanceof AssumptionViolatedException)) {
            LOGGER.severe("Test \"" + queryFile.getPath() + "\" FAILED!");
            throw new Exception("Test \"" + queryFile.getPath() + "\" FAILED!", e);
        } else {
            throw e;
        }
    }
}
Also used : IHyracksClientConnection(org.apache.hyracks.api.client.IHyracksClientConnection) InputStreamReader(java.io.InputStreamReader) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) AsterixJavaClient(org.apache.asterix.api.java.AsterixJavaClient) FileInputStream(java.io.FileInputStream) AsterixException(org.apache.asterix.common.exceptions.AsterixException) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ILangCompilationProvider(org.apache.asterix.compiler.provider.ILangCompilationProvider) BufferedReader(java.io.BufferedReader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 34 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class ResultExtractor method extract.

public static InputStream extract(InputStream resultStream) throws Exception {
    ObjectMapper om = new ObjectMapper();
    String resultStr = IOUtils.toString(resultStream, Charset.defaultCharset());
    PrettyPrinter singleLine = new SingleLinePrettyPrinter();
    ObjectNode result = om.readValue(resultStr, ObjectNode.class);
    LOGGER.fine("+++++++\n" + result + "\n+++++++\n");
    String type = "";
    String status = "";
    String results = "";
    String field = "";
    for (Iterator<String> sIter = result.fieldNames(); sIter.hasNext(); ) {
        field = sIter.next();
        switch(field) {
            case "requestID":
                break;
            case "clientContextID":
                break;
            case "signature":
                break;
            case "status":
                status = om.writeValueAsString(result.get(field));
                break;
            case "type":
                type = om.writeValueAsString(result.get(field));
                break;
            case "metrics":
                LOGGER.fine(om.writeValueAsString(result.get(field)));
                break;
            case "errors":
                JsonNode errors = result.get(field).get(0).get("msg");
                throw new AsterixException(errors.asText());
            case "results":
                if (result.get(field).size() <= 1) {
                    if (result.get(field).size() == 0) {
                        results = "";
                    } else if (result.get(field).isArray()) {
                        if (result.get(field).get(0).isTextual()) {
                            results = result.get(field).get(0).asText();
                        } else {
                            ObjectMapper omm = new ObjectMapper();
                            omm.setDefaultPrettyPrinter(singleLine);
                            omm.enable(SerializationFeature.INDENT_OUTPUT);
                            results = omm.writer(singleLine).writeValueAsString(result.get(field));
                        }
                    } else {
                        results = om.writeValueAsString(result.get(field));
                    }
                } else {
                    StringBuilder sb = new StringBuilder();
                    JsonNode[] fields = Iterators.toArray(result.get(field).elements(), JsonNode.class);
                    if (fields.length > 1) {
                        for (JsonNode f : fields) {
                            if (f.isObject()) {
                                sb.append(om.writeValueAsString(f));
                            } else {
                                sb.append(f.asText());
                            }
                        }
                    }
                    results = sb.toString();
                }
                break;
            default:
                throw new AsterixException("Unanticipated field \"" + field + "\"");
        }
    }
    return IOUtils.toInputStream(results);
}
Also used : PrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 35 with AsterixException

use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.

the class ResultExtractor method extractHandle.

public static String extractHandle(InputStream resultStream) throws Exception {
    final Charset utf8 = Charset.forName("UTF-8");
    ObjectMapper om = new ObjectMapper();
    String result = IOUtils.toString(resultStream, utf8);
    ObjectNode resultJson = om.readValue(result, ObjectNode.class);
    final JsonNode handle = resultJson.get("handle");
    if (handle != null) {
        return handle.asText();
    } else {
        JsonNode errors = resultJson.get("errors");
        if (errors != null) {
            JsonNode msg = errors.get(0).get("msg");
            throw new AsterixException(msg.asText());
        }
    }
    return null;
}
Also used : AsterixException(org.apache.asterix.common.exceptions.AsterixException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Charset(java.nio.charset.Charset) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

AsterixException (org.apache.asterix.common.exceptions.AsterixException)67 IOException (java.io.IOException)27 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)26 DataOutput (java.io.DataOutput)15 IPointable (org.apache.hyracks.data.std.api.IPointable)15 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)15 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)14 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)14 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)14 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)14 ATypeTag (org.apache.asterix.om.types.ATypeTag)10 IAType (org.apache.asterix.om.types.IAType)10 ARecordType (org.apache.asterix.om.types.ARecordType)9 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)9 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)9 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)8 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)8 List (java.util.List)7 InputStream (java.io.InputStream)5 CompilationException (org.apache.asterix.common.exceptions.CompilationException)5