Search in sources :

Example 1 with AsterixJavaClient

use of org.apache.asterix.api.java.AsterixJavaClient in project asterixdb by apache.

the class AsterixClientDriver method main.

public static void main(String[] args) throws Exception {
    AsterixClientConfig acc = new AsterixClientConfig();
    CmdLineParser cmdParser = new CmdLineParser(acc);
    try {
        cmdParser.parseArgument(args);
    } catch (Exception e) {
        cmdParser.printUsage(System.err);
        throw e;
    }
    if (acc.getArguments().isEmpty()) {
        System.err.println("Please specify the file containing the query.");
        return;
    }
    if (acc.getArguments().size() > 1) {
        System.err.print("Too many arguments. ");
        System.err.println("Only the file contained the query needs to be specified.");
        return;
    }
    boolean exec = new Boolean(acc.execute);
    IHyracksClientConnection hcc = exec ? new HyracksConnection("localhost", acc.hyracksPort) : null;
    AsterixJavaClient q = compileQuery(hcc, acc.getArguments().get(0), new Boolean(acc.optimize), new Boolean(acc.onlyPhysical), exec || new Boolean(acc.hyracksJob));
    if (exec) {
        q.execute();
    }
}
Also used : AsterixClientConfig(org.apache.asterix.api.common.AsterixClientConfig) IHyracksClientConnection(org.apache.hyracks.api.client.IHyracksClientConnection) CmdLineParser(org.kohsuke.args4j.CmdLineParser) HyracksConnection(org.apache.hyracks.api.client.HyracksConnection) AsterixJavaClient(org.apache.asterix.api.java.AsterixJavaClient)

Example 2 with AsterixJavaClient

use of org.apache.asterix.api.java.AsterixJavaClient 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 3 with AsterixJavaClient

use of org.apache.asterix.api.java.AsterixJavaClient 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 4 with AsterixJavaClient

use of org.apache.asterix.api.java.AsterixJavaClient in project asterixdb by apache.

the class AsterixCLI method main.

public static void main(String[] args) throws Exception {
    Options options = new Options();
    CmdLineParser parser = new CmdLineParser(options);
    parser.parseArgument(args);
    ILangCompilationProvider compilationProvider = new AqlCompilationProvider();
    setUp(options);
    try {
        for (String queryFile : options.args) {
            Reader in = new FileReader(queryFile);
            AsterixJavaClient ajc = new AsterixJavaClient((ICcApplicationContext) integrationUtil.cc.getApplicationContext(), integrationUtil.getHyracksClientConnection(), in, compilationProvider, new DefaultStatementExecutorFactory(), new StorageComponentProvider());
            try {
                ajc.compile(true, false, false, false, false, true, false);
            } finally {
                in.close();
            }
            ajc.execute();
        }
    } finally {
        tearDown();
    }
    System.exit(0);
}
Also used : AqlCompilationProvider(org.apache.asterix.compiler.provider.AqlCompilationProvider) CmdLineParser(org.kohsuke.args4j.CmdLineParser) DefaultStatementExecutorFactory(org.apache.asterix.app.translator.DefaultStatementExecutorFactory) ILangCompilationProvider(org.apache.asterix.compiler.provider.ILangCompilationProvider) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) StorageComponentProvider(org.apache.asterix.file.StorageComponentProvider) AsterixJavaClient(org.apache.asterix.api.java.AsterixJavaClient)

Example 5 with AsterixJavaClient

use of org.apache.asterix.api.java.AsterixJavaClient in project asterixdb by apache.

the class AsterixClientDriver method compileQuery.

private static AsterixJavaClient compileQuery(IHyracksClientConnection hcc, String filename, boolean optimize, boolean onlyPhysical, boolean createBinaryRuntime) throws Exception {
    ILangCompilationProvider compilationProvider = new AqlCompilationProvider();
    FileReader reader = new FileReader(filename);
    AsterixJavaClient q = new AsterixJavaClient(null, hcc, reader, compilationProvider, new DefaultStatementExecutorFactory(), new StorageComponentProvider());
    q.compile(optimize, true, true, true, onlyPhysical, createBinaryRuntime, createBinaryRuntime);
    return q;
}
Also used : AqlCompilationProvider(org.apache.asterix.compiler.provider.AqlCompilationProvider) DefaultStatementExecutorFactory(org.apache.asterix.app.translator.DefaultStatementExecutorFactory) ILangCompilationProvider(org.apache.asterix.compiler.provider.ILangCompilationProvider) FileReader(java.io.FileReader) StorageComponentProvider(org.apache.asterix.file.StorageComponentProvider) AsterixJavaClient(org.apache.asterix.api.java.AsterixJavaClient)

Aggregations

AsterixJavaClient (org.apache.asterix.api.java.AsterixJavaClient)5 Reader (java.io.Reader)3 DefaultStatementExecutorFactory (org.apache.asterix.app.translator.DefaultStatementExecutorFactory)3 AqlCompilationProvider (org.apache.asterix.compiler.provider.AqlCompilationProvider)3 ILangCompilationProvider (org.apache.asterix.compiler.provider.ILangCompilationProvider)3 StorageComponentProvider (org.apache.asterix.file.StorageComponentProvider)3 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 FileReader (java.io.FileReader)2 InputStreamReader (java.io.InputStreamReader)2 AsterixException (org.apache.asterix.common.exceptions.AsterixException)2 IHyracksClientConnection (org.apache.hyracks.api.client.IHyracksClientConnection)2 Test (org.junit.Test)2 CmdLineParser (org.kohsuke.args4j.CmdLineParser)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 AsterixClientConfig (org.apache.asterix.api.common.AsterixClientConfig)1 HyracksConnection (org.apache.hyracks.api.client.HyracksConnection)1 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)1