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();
}
}
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();
}
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;
}
}
}
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);
}
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;
}
Aggregations