You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hy...@apache.org on 2013/07/02 16:16:14 UTC
[20/51] [partial] TAJO-22: The package prefix should be
org.apache.tajo. (DaeMyung Kang via hyunsik)
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/BenchmarkSet.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/BenchmarkSet.java b/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/BenchmarkSet.java
deleted file mode 100644
index 9deea32..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/BenchmarkSet.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.benchmark;
-
-import com.google.protobuf.ServiceException;
-import org.apache.hadoop.net.NetUtils;
-import tajo.catalog.CatalogConstants;
-import tajo.catalog.Schema;
-import tajo.catalog.store.MemStore;
-import tajo.client.TajoClient;
-import tajo.conf.TajoConf;
-import tajo.conf.TajoConf.ConfVars;
-import tajo.util.FileUtil;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-public abstract class BenchmarkSet {
- protected TajoClient tajo;
- protected Map<String, Schema> schemas = new HashMap<String, Schema>();
- protected Map<String, Schema> outSchemas = new HashMap<String, Schema>();
- protected Map<String, String> queries = new HashMap<String, String>();
- protected String dataDir;
-
- public void init(TajoConf conf, String dataDir) throws IOException {
- this.dataDir = dataDir;
- if (System.getProperty(ConfVars.TASKRUNNER_LISTENER_ADDRESS.varname) != null) {
- tajo = new TajoClient(NetUtils.createSocketAddr(
- System.getProperty(ConfVars.TASKRUNNER_LISTENER_ADDRESS.varname)));
- } else {
- conf.set(CatalogConstants.STORE_CLASS, MemStore.class.getCanonicalName());
- tajo = new TajoClient(conf);
- }
- }
-
- protected void loadQueries(String dir) throws IOException {
- File queryDir = new File(dir);
-
- int last;
- String name, query;
- for (String file : queryDir.list()) {
- if (file.endsWith(".tql")) {
- last = file.indexOf(".tql");
- name = file.substring(0, last);
- query = FileUtil.readTextFile(new File(queryDir + "/" + file));
- }
- }
- }
-
- public abstract void loadSchemas();
-
- public abstract void loadOutSchema();
-
- public abstract void loadQueries() throws IOException;
-
- public abstract void loadTables() throws ServiceException;
-
- public String [] getTableNames() {
- return schemas.keySet().toArray(new String[schemas.size()]);
- }
-
- public String getQuery(String queryName) {
- return queries.get(queryName);
- }
-
- public Schema getSchema(String name) {
- return schemas.get(name);
- }
-
- public Iterable<Schema> getSchemas() {
- return schemas.values();
- }
-
- public Schema getOutSchema(String name) {
- return outSchemas.get(name);
- }
-
- public void perform(String queryName) throws IOException, ServiceException {
- String query = getQuery(queryName);
- if (query == null) {
- throw new IllegalArgumentException("#{queryName} does not exists");
- }
- long start = System.currentTimeMillis();
- tajo.executeQuery(query);
- long end = System.currentTimeMillis();
-
- System.out.println("====================================");
- System.out.println("QueryName: " + queryName);
- System.out.println("Query: " + query);
- System.out.println("Processing Time: " + (end - start));
- System.out.println("====================================");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/Driver.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/Driver.java b/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/Driver.java
deleted file mode 100644
index 69b9a18..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/Driver.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.benchmark;
-
-import tajo.conf.TajoConf;
-
-public class Driver {
- private static void printUsage() {
- System.out.println("benchmark BenchmarkClass datadir query");
- }
-
- public static void main(String [] args) throws Exception {
-
- if (args.length < 3) {
- printUsage();
- System.exit(-1);
- }
-
- TajoConf conf = new TajoConf();
- Class clazz = Class.forName(args[0]);
- BenchmarkSet benchmark = (BenchmarkSet) clazz.newInstance();
-
- benchmark.init(conf, args[1]);
- benchmark.loadSchemas();
- benchmark.loadQueries();
- benchmark.loadTables();
- benchmark.perform(args[2]);
- System.exit(0);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/SimpleQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/SimpleQuery.java b/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/SimpleQuery.java
deleted file mode 100644
index 9feae05..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/SimpleQuery.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.benchmark;
-
-import java.io.IOException;
-
-public class SimpleQuery extends TPCH {
- private final String BENCHMARK_DIR = "benchmark/simple";
-
- public void loadQueries() throws IOException {
- loadQueries(BENCHMARK_DIR);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/TPCH.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/TPCH.java b/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/TPCH.java
deleted file mode 100644
index ae68bb0..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/benchmark/TPCH.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.benchmark;
-
-import com.google.protobuf.ServiceException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.fs.Path;
-import tajo.catalog.CatalogUtil;
-import tajo.catalog.Schema;
-import tajo.catalog.TableMeta;
-import tajo.catalog.proto.CatalogProtos.StoreType;
-import tajo.common.TajoDataTypes.Type;
-import tajo.storage.CSVFile;
-
-import java.io.IOException;
-
-public class TPCH extends BenchmarkSet {
- private final Log LOG = LogFactory.getLog(TPCH.class);
- private final String BENCHMARK_DIR = "benchmark/tpch";
-
- public static String LINEITEM = "lineitem";
- public static String CUSTOMER = "customer";
- public static String NATION = "nation";
- public static String PART = "part";
- public static String REGION = "region";
- public static String ORDERS = "orders";
- public static String PARTSUPP = "partsupp";
- public static String SUPPLIER = "supplier";
-
- @Override
- public void loadSchemas() {
- Schema lineitem = new Schema()
- .addColumn("l_orderkey", Type.INT8) // 0
- .addColumn("l_partkey", Type.INT4) // 1
- .addColumn("l_suppkey", Type.INT4) // 2
- .addColumn("l_linenumber", Type.INT4) // 3
- .addColumn("l_quantity", Type.FLOAT4) // 4
- .addColumn("l_extendedprice", Type.FLOAT4) // 5
- .addColumn("l_discount", Type.FLOAT4) // 6
- .addColumn("l_tax", Type.FLOAT4) // 7
- // TODO - This is temporal solution. 8 and 9 are actually Char type.
- .addColumn("l_returnflag", Type.TEXT) // 8
- .addColumn("l_linestatus", Type.TEXT) // 9
- // TODO - This is temporal solution. 10,11, and 12 are actually Date type.
- .addColumn("l_shipdate", Type.TEXT) // 10
- .addColumn("l_commitdate", Type.TEXT) // 11
- .addColumn("l_receiptdate", Type.TEXT) // 12
- .addColumn("l_shipinstruct", Type.TEXT) // 13
- .addColumn("l_shipmode", Type.TEXT) // 14
- .addColumn("l_comment", Type.TEXT); // 15
- schemas.put(LINEITEM, lineitem);
-
- Schema customer = new Schema()
- .addColumn("c_custkey", Type.INT4) // 0
- .addColumn("c_name", Type.TEXT) // 1
- .addColumn("c_address", Type.TEXT) // 2
- .addColumn("c_nationkey", Type.INT4) // 3
- .addColumn("c_phone", Type.TEXT) // 4
- .addColumn("c_acctbal", Type.FLOAT4) // 5
- .addColumn("c_mktsegment", Type.TEXT) // 6
- .addColumn("c_comment", Type.TEXT); // 7
- schemas.put(CUSTOMER, customer);
-
- Schema nation = new Schema()
- .addColumn("n_nationkey", Type.INT4) // 0
- .addColumn("n_name", Type.TEXT) // 1
- .addColumn("n_regionkey", Type.INT4) // 2
- .addColumn("n_comment", Type.TEXT); // 3
- schemas.put(NATION, nation);
-
- Schema part = new Schema()
- .addColumn("p_partkey", Type.INT4) // 0
- .addColumn("p_name", Type.TEXT) // 1
- .addColumn("p_mfgr", Type.TEXT) // 2
- .addColumn("p_brand", Type.TEXT) // 3
- .addColumn("p_type", Type.TEXT) // 4
- .addColumn("p_size", Type.INT4) // 5
- .addColumn("p_container", Type.TEXT) // 6
- .addColumn("p_retailprice", Type.FLOAT4) // 7
- .addColumn("p_comment", Type.TEXT); // 8
- schemas.put(PART, part);
-
- Schema region = new Schema()
- .addColumn("r_regionkey", Type.INT4) // 0
- .addColumn("r_name", Type.TEXT) // 1
- .addColumn("r_comment", Type.TEXT); // 2
- schemas.put(REGION, region);
-
- Schema orders = new Schema()
- .addColumn("o_orderkey", Type.INT4) // 0
- .addColumn("o_custkey", Type.INT4) // 1
- .addColumn("o_orderstatus", Type.TEXT) // 2
- .addColumn("o_totalprice", Type.FLOAT4) // 3
- // TODO - This is temporal solution. o_orderdate is actually Date type.
- .addColumn("o_orderdate", Type.TEXT) // 4
- .addColumn("o_orderpriority", Type.TEXT) // 5
- .addColumn("o_clerk", Type.TEXT) // 6
- .addColumn("o_shippriority", Type.INT4) // 7
- .addColumn("o_comment", Type.TEXT); // 8
- schemas.put(ORDERS, orders);
-
- Schema partsupp = new Schema()
- .addColumn("ps_partkey", Type.INT4) // 0
- .addColumn("ps_suppkey", Type.INT4) // 1
- .addColumn("ps_availqty", Type.INT4) // 2
- .addColumn("ps_supplycost", Type.FLOAT4) // 3
- .addColumn("ps_comment", Type.TEXT); // 4
- schemas.put(PARTSUPP, partsupp);
-
- Schema supplier = new Schema()
- .addColumn("s_suppkey", Type.INT4) // 0
- .addColumn("s_name", Type.TEXT) // 1
- .addColumn("s_address", Type.TEXT) // 2
- .addColumn("s_nationkey", Type.INT4) // 3
- .addColumn("s_phone", Type.TEXT) // 4
- .addColumn("s_acctbal", Type.FLOAT4) // 5
- .addColumn("s_comment", Type.TEXT); // 6
- schemas.put(SUPPLIER, supplier);
- }
-
- public void loadOutSchema() {
- Schema q2 = new Schema()
- .addColumn("s_acctbal", Type.FLOAT4)
- .addColumn("s_name", Type.TEXT)
- .addColumn("n_name", Type.TEXT)
- .addColumn("p_partkey", Type.INT4)
- .addColumn("p_mfgr", Type.TEXT)
- .addColumn("s_address", Type.TEXT)
- .addColumn("s_phone", Type.TEXT)
- .addColumn("s_comment", Type.TEXT);
- outSchemas.put("q2", q2);
- }
-
- public void loadQueries() throws IOException {
- loadQueries(BENCHMARK_DIR);
- }
-
- public void loadTables() throws ServiceException {
- loadTable(LINEITEM);
- loadTable(CUSTOMER);
- loadTable(NATION);
- loadTable(PART);
- loadTable(REGION);
- loadTable(ORDERS);
- loadTable(PARTSUPP) ;
- loadTable(SUPPLIER);
- }
-
- private void loadTable(String tableName) throws ServiceException {
- TableMeta meta = CatalogUtil.newTableMeta(getSchema(tableName), StoreType.CSV);
- meta.putOption(CSVFile.DELIMITER, "|");
- tajo.createTable(tableName, new Path(dataDir, tableName), meta);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/cli/TajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/cli/TajoCli.java b/tajo-core/tajo-core-backend/src/main/java/tajo/cli/TajoCli.java
deleted file mode 100644
index 550e8f2..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/cli/TajoCli.java
+++ /dev/null
@@ -1,382 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.cli;
-
-import com.google.protobuf.ServiceException;
-import jline.console.ConsoleReader;
-import jline.console.history.FileHistory;
-import jline.console.history.PersistentHistory;
-import org.apache.commons.cli.*;
-import org.apache.commons.lang.StringUtils;
-import tajo.QueryId;
-import tajo.TajoProtos.QueryState;
-import tajo.catalog.Column;
-import tajo.catalog.TableDesc;
-import tajo.client.ClientProtocol;
-import tajo.client.QueryStatus;
-import tajo.client.TajoClient;
-import tajo.conf.TajoConf;
-import tajo.conf.TajoConf.ConfVars;
-import tajo.master.cluster.ServerName;
-import tajo.util.FileUtil;
-import tajo.util.TajoIdUtils;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.util.List;
-
-public class TajoCli {
- private final TajoConf conf;
- private static final Options options;
- private TajoClient client;
-
- private String entryAddr;
- private static final int PRINT_LIMIT = 24;
-
- private ConsoleReader reader;
- private InputStream sin;
- private OutputStream out;
- private PrintWriter sout;
-
-
- static {
- options = new Options();
- options.addOption("a", "addr", true, "client service address (hostname:port)");
- options.addOption("conf", true, "user configuration dir");
- options.addOption("h", "help", false, "help");
- }
-
- public TajoCli(TajoConf c, String [] args,
- InputStream in, OutputStream out) throws Exception {
- this.conf = new TajoConf(c);
- this.sin = in;
- this.out = out;
- this.reader = new ConsoleReader(sin, out);
- this.sout = new PrintWriter(reader.getOutput());
-
- CommandLineParser parser = new PosixParser();
- CommandLine cmd = parser.parse(options, args);
-
- String historyFile = ".tajo_history";
- String historyDirectory = System.getProperty("user.home");
-
- try {
- if ((new File(historyDirectory)).exists()) {
- String historyPath = historyDirectory + File.separator + historyFile;
- reader.setHistory(new FileHistory(new File(historyPath)));
- } else {
- System.err.println("Home directory : '" + historyDirectory +"' does not exist.");
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
-
- if (cmd.hasOption("h")) {
- printUsage();
- System.exit(-1);
- }
-
- // firstly, the specific address (option -a) is used
- String addr;
- if (entryAddr == null && cmd.hasOption("a")) {
- addr = cmd.getOptionValue("a");
- ServerName sn = ServerName.createWithDefaultPort(addr,
- conf.getIntVar(TajoConf.ConfVars.CLIENT_SERVICE_PORT));
-
- this.entryAddr = sn.getServerName();
- conf.setVar(TajoConf.ConfVars.CLIENT_SERVICE_ADDRESS, this.entryAddr);
- }
-
- // if there is no "-a" option,
- if(this.entryAddr == null) {
- if (conf.getVar(ConfVars.CLIENT_SERVICE_ADDRESS) != null &&
- conf.getBoolVar(ConfVars.CLUSTER_DISTRIBUTED)) {
- // it checks if the client service address is given in configuration and distributed mode.
- // if so, it sets entryAddr.
- entryAddr = conf.getVar(ConfVars.CLIENT_SERVICE_ADDRESS);
- }
- }
-
- // if the remote tajo cluster is set, entryAddr is not null.
- if (entryAddr != null) {
- conf.setBoolVar(ConfVars.CLUSTER_DISTRIBUTED, true);
- }
-
- if (entryAddr != null) {
- sout.println("Trying to connect the tajo master (" + entryAddr + ")");
- } else {
- sout.println("Executing the tajo cluster in local mode");
- }
- client = new TajoClient(conf);
- }
-
- public int runShell() throws Exception {
-
- String line;
- String prefix = "";
- String prompt = "tajo";
- String curPrompt = prompt;
- int code = 0;
-
- while((line = reader.readLine(curPrompt + "> ")) != null) {
- if (!prefix.equals("")) {
- prefix += '\n';
- }
- if (line.trim().endsWith(";") && !line.trim().endsWith("\\;")) {
- line = prefix + line;
- code = executeShell(line);
- ((PersistentHistory)reader.getHistory()).flush();
- prefix = "";
- curPrompt = prompt;
- } else {
- prefix = prefix + line;
- curPrompt = StringUtils.repeat(" ", prompt.length());
- continue;
- }
- }
- return code;
- }
-
- public int executeShell(String line) throws Exception {
-
- String cmd [];
- String command = "";
- for (String oneCmd : line.split(";")) {
- if (StringUtils.endsWith(oneCmd, "\\")) {
- command += StringUtils.chop(oneCmd) + ";";
- continue;
- } else {
- command += oneCmd;
- }
- if (StringUtils.isBlank(command)) {
- continue;
- }
-
- cmd = command.split(" ");
- if (cmd[0].equalsIgnoreCase("exit") || cmd[0].equalsIgnoreCase("quit")) {
- sout.println("\n\nbye from data deluge...");
- sout.flush();
- ((PersistentHistory)this.reader.getHistory()).flush();
- System.exit(0);
- } else if (cmd[0].equalsIgnoreCase("/c")) {
- clusterInfo();
- } else if (cmd[0].equalsIgnoreCase("/t")) {
- showTables();
- } else if (cmd[0].equalsIgnoreCase("/d")) {
- descTable(cmd);
- } else if (cmd[0].equalsIgnoreCase("attach")) {
- attachTable(cmd);
- } else if (cmd[0].equalsIgnoreCase("detach")) {
- detachTable(cmd);
- } else if (cmd[0].equalsIgnoreCase("history")) {
-
- } else {
- ClientProtocol.SubmitQueryRespose response = client.executeQuery(command);
-
- if (response.getResultCode() == ClientProtocol.ResultCode.OK) {
- QueryId queryId = new QueryId(response.getQueryId());
- if (queryId.equals(TajoIdUtils.NullQueryId)) {
- sout.println("OK");
- } else {
- getQueryResult(queryId);
- }
- } else {
- if (response.hasErrorMessage()) {
- sout.println(response.getErrorMessage());
- }
- }
- }
- command = "";
- }
- return 0;
- }
-
- private boolean isFailed(QueryState state) {
- return state == QueryState.QUERY_ERROR || state == QueryState.QUERY_FAILED;
- }
-
- private void getQueryResult(QueryId queryId) {
- // if query is empty string
- if (queryId.equals(TajoIdUtils.NullQueryId)) {
- return;
- }
-
- // query execute
- try {
-
- QueryStatus status;
- while (true) {
- Thread.sleep(1000);
- status = client.getQueryStatus(queryId);
- if (status.getState() == QueryState.QUERY_RUNNING ||
- status.getState() == QueryState.QUERY_SUCCEEDED) {
- sout.println("Progress: " + (int)(status.getProgress() * 100.0f)
- + "%, response time: " + ((float)(status.getFinishTime() - status.getSubmitTime())
- / 1000.0) + " sec");
- sout.flush();
- }
-
- if (status.getState() != QueryState.QUERY_RUNNING) {
- break;
- }
- }
-
- if (isFailed(status.getState())) {
- sout.println(status.getErrorMessage());
- } else if (status.getState() == QueryState.QUERY_KILLED) {
- sout.println(queryId + " is killed.");
- } else {
- if (status.getState() == QueryState.QUERY_SUCCEEDED) {
- ResultSet res = client.getQueryResult(queryId);
- if (res == null) {
- sout.println("OK");
- return;
- }
-
- ResultSetMetaData rsmd = res.getMetaData();
- TableDesc desc = client.getResultDesc(queryId);
- sout.println("final state: " + status.getState()
- + ", init time: " + (((float)(status.getInitTime() - status.getSubmitTime())
- / 1000.0) + " sec")
- + ", execution time: " + (((float)status.getFinishTime() - status.getInitTime())
- / 1000.0) + " sec"
- + ", total response time: " + (((float)(status.getFinishTime() -
- status.getSubmitTime()) / 1000.0) + " sec"));
- sout.println("result: " + desc.getPath() + "\n");
-
- int numOfColumns = rsmd.getColumnCount();
- for (int i = 1; i <= numOfColumns; i++) {
- if (i > 1) sout.print(", ");
- String columnName = rsmd.getColumnName(i);
- sout.print(columnName);
- }
- sout.println("\n-------------------------------");
-
- int numOfPrintedRows = 0;
- while (res.next()) {
- // TODO - to be improved to print more formatted text
- for (int i = 1; i <= numOfColumns; i++) {
- if (i > 1) sout.print(", ");
- String columnValue = res.getObject(i).toString();
- sout.print(columnValue);
- }
- sout.println();
- sout.flush();
- numOfPrintedRows++;
- if (numOfPrintedRows >= PRINT_LIMIT) {
- sout.print("continue... ('q' is quit)");
- sout.flush();
- if (sin.read() == 'q') {
- break;
- }
- numOfPrintedRows = 0;
- sout.println();
- }
- }
- }
- }
- } catch (Throwable t) {
- t.printStackTrace();
- System.err.println(t.getMessage());
- }
- }
-
- private void clusterInfo() {
- List<String> list = client.getClusterInfo();
- for(String server : list) {
- sout.println(server);
- }
- }
-
- private void showTables() throws ServiceException {
- List<String> tableList = client.getTableList();
- for (String table : tableList) {
- sout.println(table);
- }
- }
-
- private void descTable(String [] cmd) throws ServiceException {
- if (cmd.length > 1) {
- TableDesc desc = client.getTableDesc(cmd[1]);
- if (desc == null) {
- sout.println("No such a table name: " + cmd[1]);
- } else {
- sout.println(toFormattedString(desc));
- }
- } else {
- sout.println("Table name is required");
- }
- }
-
- private void attachTable(String [] cmd) throws Exception {
- if(cmd.length != 3) {
- sout.println("usage: attach tablename path");
- } else {
- client.attachTable(cmd[1], cmd[2]);
- sout.println("attached " + cmd[1] + " (" + cmd[2] + ")");
- }
- }
-
- private void detachTable(String [] cmd) throws Exception {
- if (cmd.length != 2) {
- System.out.println("usage: detach tablename");
- } else {
- client.detachTable(cmd[1]);
- sout.println("detached " + cmd[1] + " from tajo");
- }
- }
-
- private static String toFormattedString(TableDesc desc) {
- StringBuilder sb = new StringBuilder();
- sb.append("\ntable name: ").append(desc.getId()).append("\n");
- sb.append("table path: ").append(desc.getPath()).append("\n");
- sb.append("store type: ").append(desc.getMeta().getStoreType()).append("\n");
- if (desc.getMeta().getStat() != null) {
- sb.append("number of rows: ").append(desc.getMeta().getStat().getNumRows()).append("\n");
- sb.append("volume (bytes): ").append(
- FileUtil.humanReadableByteCount(desc.getMeta().getStat().getNumBytes(),
- true)).append("\n");
- }
- sb.append("schema: \n");
-
- for(int i = 0; i < desc.getMeta().getSchema().getColumnNum(); i++) {
- Column col = desc.getMeta().getSchema().getColumn(i);
- sb.append(col.getColumnName()).append("\t").append(col.getDataType());
- sb.append("\n");
- }
- return sb.toString();
- }
-
- private void printUsage() {
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp( "tajo shell [options]", options );
- }
-
- public static void main(String [] args) throws Exception {
- TajoConf conf = new TajoConf();
- TajoCli shell = new TajoCli(conf, args, System.in, System.out);
- System.out.println();
- int status = shell.runShell();
- System.exit(status);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/client/QueryStatus.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/client/QueryStatus.java b/tajo-core/tajo-core-backend/src/main/java/tajo/client/QueryStatus.java
deleted file mode 100644
index 27895c5..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/client/QueryStatus.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.client;
-
-import tajo.QueryId;
-import tajo.TajoProtos.QueryState;
-import tajo.client.ClientProtocol.GetQueryStatusResponse;
-
-public class QueryStatus {
- private QueryId queryId;
- private QueryState state;
- private float progress;
- private long submitTime;
- private long initTime;
- private long finishTime;
- private boolean hasResult;
- private String errorText;
-
- public QueryStatus(GetQueryStatusResponse proto) {
- queryId = new QueryId(proto.getQueryId());
- state = proto.getState();
- progress = proto.getProgress();
- submitTime = proto.getSubmitTime();
- initTime = proto.getInitTime();
- finishTime = proto.getFinishTime();
- hasResult = proto.getHasResult();
- if (proto.hasErrorMessage()) {
- errorText = proto.getErrorMessage();
- }
- }
-
- public QueryId getQueryId() {
- return this.queryId;
- }
-
- public QueryState getState() {
- return this.state;
- }
-
- public float getProgress() {
- return progress;
- }
-
- public long getSubmitTime() {
- return this.submitTime;
- }
-
- public long getInitTime() {
- return this.initTime;
- }
-
- public long getFinishTime() {
- return this.finishTime;
- }
-
- public boolean hasResult() {
- return this.hasResult;
- }
-
- public String getErrorMessage() {
- return errorText;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/client/ResultSetUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/client/ResultSetUtil.java b/tajo-core/tajo-core-backend/src/main/java/tajo/client/ResultSetUtil.java
deleted file mode 100644
index d79181f..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/client/ResultSetUtil.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.client;
-
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-
-public class ResultSetUtil {
- public static String prettyFormat(ResultSet res) throws SQLException {
- StringBuilder sb = new StringBuilder();
- ResultSetMetaData rsmd = res.getMetaData();
- int numOfColumns = rsmd.getColumnCount();
-
- for (int i = 1; i <= numOfColumns; i++) {
- if (i > 1) sb.append(", ");
- String columnName = rsmd.getColumnName(i);
- sb.append(columnName);
- }
- sb.append("\n-------------------------------\n");
-
- while (res.next()) {
- for (int i = 1; i <= numOfColumns; i++) {
- if (i > 1) sb.append(", ");
- String columnValue = res.getObject(i).toString();
- sb.append(columnValue);
- }
- sb.append("\n");
- }
-
- return sb.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/client/TajoClient.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/client/TajoClient.java b/tajo-core/tajo-core-backend/src/main/java/tajo/client/TajoClient.java
deleted file mode 100644
index a022541..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/client/TajoClient.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.client;
-
-import com.google.protobuf.ServiceException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.net.NetUtils;
-import tajo.QueryId;
-import tajo.TajoProtos.QueryState;
-import tajo.catalog.CatalogUtil;
-import tajo.catalog.TableDesc;
-import tajo.catalog.TableMeta;
-import tajo.client.ClientProtocol.*;
-import tajo.conf.TajoConf;
-import tajo.conf.TajoConf.ConfVars;
-import tajo.engine.query.ResultSetImpl;
-import tajo.rpc.ProtoBlockingRpcClient;
-import tajo.rpc.protocolrecords.PrimitiveProtos.StringProto;
-import tajo.util.TajoIdUtils;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.sql.ResultSet;
-import java.util.List;
-
-public class TajoClient {
- private final Log LOG = LogFactory.getLog(TajoClient.class);
-
- private final TajoConf conf;
- private ProtoBlockingRpcClient client;
- private ClientProtocolService.BlockingInterface service;
-
- public TajoClient(TajoConf conf) throws IOException {
- this.conf = conf;
- String masterAddr = this.conf.getVar(ConfVars.CLIENT_SERVICE_ADDRESS);
- InetSocketAddress addr = NetUtils.createSocketAddr(masterAddr);
- connect(addr);
- }
-
- public TajoClient(InetSocketAddress addr) throws IOException {
- this.conf = new TajoConf();
- connect(addr);
- }
-
- public TajoClient(String hostname, int port) throws IOException {
- this.conf = new TajoConf();
- connect(NetUtils.createSocketAddr(hostname, port));
- }
-
- private void connect(InetSocketAddress addr) throws IOException {
- try {
- client = new ProtoBlockingRpcClient(ClientProtocol.class, addr);
- service = client.getStub();
- } catch (Exception e) {
- throw new IOException(e);
- }
-
- LOG.info("connected to tajo cluster (" +
- tajo.util.NetUtils.getIpPortString(addr) + ")");
- }
-
- public void close() {
- client.close();
- }
-
- public boolean isConnected() {
- return client.isConnected();
- }
-
- /**
- * It submits a query statement and get a response immediately.
- * The response only contains a query id, and submission status.
- * In order to get the result, you should use {@link #getQueryResult(tajo.QueryId)}
- * or {@link #getQueryResultAndWait(tajo.QueryId)}.
- */
- public SubmitQueryRespose executeQuery(String tql) throws ServiceException {
- QueryRequest.Builder builder = QueryRequest.newBuilder();
- builder.setQuery(tql);
-
- return service.submitQuery(null, builder.build());
- }
-
- /**
- * It submits a query statement and get a response.
- * The main difference from {@link #executeQuery(String)}
- * is a blocking method. So, this method is wait for
- * the finish of the submitted query.
- *
- * @return If failed, return null.
- */
- public ResultSet executeQueryAndGetResult(String tql)
- throws ServiceException, IOException {
- QueryRequest.Builder builder = QueryRequest.newBuilder();
- builder.setQuery(tql);
- SubmitQueryRespose response = service.submitQuery(null, builder.build());
- QueryId queryId = new QueryId(response.getQueryId());
- if (queryId.equals(TajoIdUtils.NullQueryId)) {
- return null;
- }
-
- return getQueryResultAndWait(queryId);
- }
-
- public QueryStatus getQueryStatus(QueryId queryId) throws ServiceException {
- GetQueryStatusRequest.Builder builder
- = GetQueryStatusRequest.newBuilder();
- builder.setQueryId(queryId.getProto());
-
- GetQueryStatusResponse res = service.getQueryStatus(null,
- builder.build());
-
- return new QueryStatus(res);
- }
-
- private static boolean isQueryRunnning(QueryState state) {
- return state == QueryState.QUERY_NEW ||
- state == QueryState.QUERY_INIT ||
- state == QueryState.QUERY_RUNNING;
- }
-
- public ResultSet getQueryResult(QueryId queryId)
- throws ServiceException, IOException {
- if (queryId.equals(TajoIdUtils.NullQueryId)) {
- return null;
- }
-
- TableDesc tableDesc = getResultDesc(queryId);
- return new ResultSetImpl(conf, tableDesc.getPath());
- }
-
- public ResultSet getQueryResultAndWait(QueryId queryId)
- throws ServiceException, IOException {
- if (queryId.equals(TajoIdUtils.NullQueryId)) {
- return null;
- }
- QueryStatus status = getQueryStatus(queryId);
-
- while(status != null && isQueryRunnning(status.getState())) {
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- status = getQueryStatus(queryId);
- }
-
- if (status.getState() == QueryState.QUERY_SUCCEEDED) {
- if (status.hasResult()) {
- return getQueryResult(queryId);
- } else {
- return null;
- }
-
- } else {
- LOG.error(status.getErrorMessage());
-
- return null;
- }
- }
-
- public TableDesc getResultDesc(QueryId queryId) throws ServiceException {
- if (queryId.equals(TajoIdUtils.NullQueryId)) {
- return null;
- }
-
- GetQueryResultRequest.Builder builder = GetQueryResultRequest.newBuilder();
- builder.setQueryId(queryId.getProto());
- GetQueryResultResponse response = service.getQueryResult(null,
- builder.build());
-
- return CatalogUtil.newTableDesc(response.getTableDesc());
- }
-
- public boolean updateQuery(String tql) throws ServiceException {
- QueryRequest.Builder builder = QueryRequest.newBuilder();
- builder.setQuery(tql);
-
- ResultCode resultCode =
- service.updateQuery(null, builder.build()).getResultCode();
- return resultCode == ResultCode.OK;
- }
-
- public boolean existTable(String name) throws ServiceException {
- StringProto.Builder builder = StringProto.newBuilder();
- builder.setValue(name);
- return service.existTable(null, builder.build()).getValue();
- }
-
- public TableDesc attachTable(String name, String path)
- throws ServiceException {
- AttachTableRequest.Builder builder = AttachTableRequest.newBuilder();
- builder.setName(name);
- builder.setPath(path);
- TableResponse res = service.attachTable(null, builder.build());
- return CatalogUtil.newTableDesc(res.getTableDesc());
- }
-
- public TableDesc attachTable(String name, Path path)
- throws ServiceException {
- return attachTable(name, path.toString());
- }
-
- public boolean detachTable(String name) throws ServiceException {
- StringProto.Builder builder = StringProto.newBuilder();
- builder.setValue(name);
- return service.detachTable(null, builder.build()).getValue();
- }
-
- public TableDesc createTable(String name, Path path, TableMeta meta)
- throws ServiceException {
- CreateTableRequest.Builder builder = CreateTableRequest.newBuilder();
- builder.setName(name);
- builder.setPath(path.toString());
- builder.setMeta(meta.getProto());
- TableResponse res = service.createTable(null, builder.build());
- return CatalogUtil.newTableDesc(res.getTableDesc());
- }
-
- public boolean dropTable(String name) throws ServiceException {
- StringProto.Builder builder = StringProto.newBuilder();
- builder.setValue(name);
- return service.dropTable(null, builder.build()).getValue();
- }
-
- public List<String> getClusterInfo() {
- return null;
- }
-
- /**
- * Get a list of table names. All table and column names are
- * represented as lower-case letters.
- */
- public List<String> getTableList() throws ServiceException {
- GetTableListRequest.Builder builder = GetTableListRequest.newBuilder();
- GetTableListResponse res = service.getTableList(null, builder.build());
- return res.getTablesList();
- }
-
- public TableDesc getTableDesc(String tableName) throws ServiceException {
- GetTableDescRequest.Builder build = GetTableDescRequest.newBuilder();
- build.setTableName(tableName);
- TableResponse res = service.getTableDesc(null, build.build());
- if (res == null) {
- return null;
- } else {
- return CatalogUtil.newTableDesc(res.getTableDesc());
- }
- }
-
- public boolean killQuery(QueryId queryId)
- throws ServiceException, IOException {
-
- QueryStatus status = getQueryStatus(queryId);
-
- try {
- /* send a kill to the TM */
- service.killQuery(null, queryId.getProto());
- long currentTimeMillis = System.currentTimeMillis();
- long timeKillIssued = currentTimeMillis;
- while ((currentTimeMillis < timeKillIssued + 10000L) && (status.getState()
- != QueryState.QUERY_KILLED)) {
- try {
- Thread.sleep(1000L);
- } catch(InterruptedException ie) {
- /** interrupted, just break */
- break;
- }
- currentTimeMillis = System.currentTimeMillis();
- status = getQueryStatus(queryId);
- }
- } catch(ServiceException io) {
- LOG.debug("Error when checking for application status", io);
- return false;
- }
-
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AggFuncCallEval.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AggFuncCallEval.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AggFuncCallEval.java
deleted file mode 100644
index 805239e..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AggFuncCallEval.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.engine.eval;
-
-import com.google.gson.annotations.Expose;
-import tajo.catalog.FunctionDesc;
-import tajo.catalog.Schema;
-import tajo.catalog.function.AggFunction;
-import tajo.catalog.function.FunctionContext;
-import tajo.common.TajoDataTypes.DataType;
-import tajo.datum.Datum;
-import tajo.engine.json.GsonCreator;
-import tajo.storage.Tuple;
-import tajo.storage.VTuple;
-
-public class AggFuncCallEval extends FuncEval implements Cloneable {
- @Expose protected AggFunction instance;
- @Expose boolean firstPhase = false;
- private Tuple params;
-
- public AggFuncCallEval(FunctionDesc desc, AggFunction instance, EvalNode[] givenArgs) {
- super(Type.AGG_FUNCTION, desc, givenArgs);
- this.instance = instance;
- }
-
- @Override
- public EvalContext newContext() {
- AggFunctionCtx newCtx = new AggFunctionCtx(argEvals, instance.newContext());
-
- return newCtx;
- }
-
- @Override
- public void eval(EvalContext ctx, Schema schema, Tuple tuple) {
- AggFunctionCtx localCtx = (AggFunctionCtx) ctx;
- if (params == null) {
- this.params = new VTuple(argEvals.length);
- }
-
- if (argEvals != null) {
- params.clear();
-
- for (int i = 0; i < argEvals.length; i++) {
- argEvals[i].eval(localCtx.argCtxs[i], schema, tuple);
- params.put(i, argEvals[i].terminate(localCtx.argCtxs[i]));
- }
- }
-
- if (firstPhase) {
- instance.eval(localCtx.funcCtx, params);
- } else {
- instance.merge(localCtx.funcCtx, params);
- }
- }
-
- @Override
- public Datum terminate(EvalContext ctx) {
- if (firstPhase) {
- return instance.getPartialResult(((AggFunctionCtx)ctx).funcCtx);
- } else {
- return instance.terminate(((AggFunctionCtx)ctx).funcCtx);
- }
- }
-
- @Override
- public DataType[] getValueType() {
- if (firstPhase) {
- return instance.getPartialResultType();
- } else {
- return funcDesc.getReturnType();
- }
- }
-
- public String toJSON() {
- return GsonCreator.getInstance().toJson(this, EvalNode.class);
- }
-
- public Object clone() throws CloneNotSupportedException {
- AggFuncCallEval agg = (AggFuncCallEval) super.clone();
- return agg;
- }
-
- public void setFirstPhase() {
- this.firstPhase = true;
- }
-
- protected class AggFunctionCtx extends FuncCallCtx {
- FunctionContext funcCtx;
-
- AggFunctionCtx(EvalNode [] argEvals, FunctionContext funcCtx) {
- super(argEvals);
- this.funcCtx = funcCtx;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AlgebraicException.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AlgebraicException.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AlgebraicException.java
deleted file mode 100644
index d97afe7..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AlgebraicException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- *
- */
-package tajo.engine.eval;
-
-public class AlgebraicException extends RuntimeException {
- private static final long serialVersionUID = -1813125460274622006L;
-
- public AlgebraicException() {
- }
-
- public AlgebraicException(String message) {
- super(message);
- }
-
- public AlgebraicException(Throwable cause) {
- super(cause);
- }
-
- public AlgebraicException(String message, Throwable cause) {
- super(message, cause);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AlgebraicUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AlgebraicUtil.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AlgebraicUtil.java
deleted file mode 100644
index b886e2a..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/AlgebraicUtil.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.engine.eval;
-
-import tajo.catalog.Column;
-
-import java.util.Map;
-
-public class AlgebraicUtil {
-
- /**
- * Transpose a given comparison expression into the expression
- * where the variable corresponding to the target is placed
- * on the left-hand side.
- *
- * @param expr
- * @param target
- * @return Transposed expression
- */
- public static EvalNode transpose(EvalNode expr, Column target) {
- EvalNode commutated = null;
- // If the variable is in the right term, inverse the expr.
- if (!EvalTreeUtil.containColumnRef(expr.getLeftExpr(), target)) {
- // the commutate method works with a copy of the expr
- commutated = commutate(expr);
- } else {
- try {
- commutated = (EvalNode) expr.clone();
- } catch (CloneNotSupportedException e) {
- throw new AlgebraicException(e);
- }
- }
-
- return _transpose(commutated, target);
- }
-
- private static EvalNode _transpose(EvalNode _expr, Column target) {
- EvalNode expr = simplify(_expr);
-
- if (isSingleVar(expr.getLeftExpr())) {
- return expr;
- }
-
- EvalNode left = expr.getLeftExpr();
- EvalNode lTerm = null;
- EvalNode rTerm = null;
-
- if (left.getType() == EvalNode.Type.PLUS
- || left.getType() == EvalNode.Type.MINUS
- || left.getType() == EvalNode.Type.MULTIPLY
- || left.getType() == EvalNode.Type.DIVIDE) {
-
- // If the left-left term is a variable, the left-right term is transposed.
- if(EvalTreeUtil.containColumnRef(left.getLeftExpr(), target)) {
- PartialBinaryExpr tmpTerm = splitRightTerm(left);
- tmpTerm.type = inverseOperator(tmpTerm.type);
- tmpTerm.setLeftExpr(expr.getRightExpr());
- lTerm = left.getLeftExpr();
- rTerm = new BinaryEval(tmpTerm);
- } else {
- // Otherwise, the left-right term is transposed into the left-left term.
- PartialBinaryExpr tmpTerm = splitLeftTerm(left);
- tmpTerm.type = inverseOperator(tmpTerm.type);
- tmpTerm.setLeftExpr(expr.getRightExpr());
- lTerm = left.getRightExpr();
- rTerm = new BinaryEval(tmpTerm);
- }
- }
-
- return _transpose(new BinaryEval(expr.getType(), lTerm, rTerm), target);
- }
-
- /**
- * Inverse a given operator (+, -, *, /)
- *
- * @param type
- * @return inversed operator type
- */
- public static EvalNode.Type inverseOperator(EvalNode.Type type) {
- switch (type) {
- case PLUS:
- return EvalNode.Type.MINUS;
- case MINUS:
- return EvalNode.Type.PLUS;
- case MULTIPLY:
- return EvalNode.Type.DIVIDE;
- case DIVIDE:
- return EvalNode.Type.MULTIPLY;
- default : throw new AlgebraicException("ERROR: cannot inverse the operator: "
- + type);
- }
- }
-
- /**
- * Examine if a given expr is a variable.
- *
- * @param node
- * @return true if a given expr is a variable.
- */
- private static boolean isSingleVar(EvalNode node) {
- if (node.getType() == EvalNode.Type.FIELD) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Simplify the given expr. That is, all subexprs consisting of only constants
- * are calculated immediately.
- *
- * @param expr to be simplified
- * @return the simplified expr
- */
- public static EvalNode simplify(EvalNode expr) {
- EvalNode left = expr.getLeftExpr();
- EvalNode right = expr.getRightExpr();
-
- switch (expr.getType()) {
- case AND:
- case OR:
- case EQUAL:
- case LTH:
- case LEQ:
- case GTH:
- case GEQ:
- left = simplify(left);
- right = simplify(right);
- return new BinaryEval(expr.getType(), left, right);
-
- case PLUS:
- case MINUS:
- case MULTIPLY:
- case DIVIDE:
- left = simplify(left);
- right = simplify(right);
-
- // If both are constants, they can be evaluated immediately.
- if (left.getType() == EvalNode.Type.CONST
- && right.getType() == EvalNode.Type.CONST) {
- EvalContext exprCtx = expr.newContext();
- expr.eval(exprCtx, null, null);
- return new ConstEval(expr.terminate(exprCtx));
- } else {
- return new BinaryEval(expr.getType(), left, right);
- }
-
- case CONST:
- return expr;
-
- default: new AlgebraicException("Wrong expression: " + expr);
- }
- return expr;
- }
-
- /**
- * @param expr to be evaluated if the expr includes one variable
- * @return true if expr has only one field
- */
- public static boolean containSingleVar(EvalNode expr) {
- Map<EvalNode.Type, Integer> counter = EvalTreeUtil.getExprCounters(expr);
-
- int sum = 0;
- for (Integer cnt : counter.values()) {
- sum += cnt;
- }
-
- if (sum == 1 && counter.get(EvalNode.Type.FIELD) == 1) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Split the left term and transform it into the right deep expression.
- *
- * @param expr - notice the left term of this expr will be eliminated
- * after done.
- * @return the separated expression changed into the right deep expression.
- * For example, the expr 'x * y' is transformed into '* x'.
- *
- */
- public static PartialBinaryExpr splitLeftTerm(EvalNode expr) {
-
- if (!(expr.getType() == EvalNode.Type.PLUS
- || expr.getType() == EvalNode.Type.MINUS
- || expr.getType() == EvalNode.Type.MULTIPLY
- || expr.getType() == EvalNode.Type.DIVIDE)) {
- throw new AlgebraicException("Invalid algebraic operation: " + expr);
- }
-
- if (expr.getLeftExpr().getType() != EvalNode.Type.CONST) {
- return splitLeftTerm(expr.getLeftExpr());
- }
-
- PartialBinaryExpr splitted =
- new PartialBinaryExpr(expr.getType(), null, expr.getLeftExpr());
- expr.setLeftExpr(null);
- return splitted;
- }
-
- /**
- * Split the left term and transform it into the right deep expression.
- *
- * @param expr - to be splited
- * @return the separated expression changed into the right deep expression.
- * For example, the expr 'x * y' is transformed into '* y'.
- *
- * @throws CloneNotSupportedException
- */
- public static PartialBinaryExpr splitRightTerm(EvalNode expr) {
-
- if (!(expr.getType() == EvalNode.Type.PLUS
- || expr.getType() == EvalNode.Type.MINUS
- || expr.getType() == EvalNode.Type.MULTIPLY
- || expr.getType() == EvalNode.Type.DIVIDE)) {
- throw new AlgebraicException("Invalid algebraic operation: " + expr);
- }
-
- if (expr.getRightExpr().getType() != EvalNode.Type.CONST) {
- return splitRightTerm(expr.getRightExpr());
- }
-
- PartialBinaryExpr splitted =
- new PartialBinaryExpr(expr.getType(), null, expr.getRightExpr());
- expr.setRightExpr(null);
- return splitted;
- }
-
- /**
- * Commutate two terms which are added, subtracted and multiplied.
- *
- * @param inputExpr
- * @return
- */
- public static EvalNode commutate(EvalNode inputExpr) {
- EvalNode expr;
- switch (inputExpr.getType()) {
- case AND:
- case OR:
- case EQUAL:
- case PLUS:
- case MINUS:
- case MULTIPLY: // these types can be commutated w/o any change
- expr = EvalTreeFactory.create(inputExpr.getType(),
- inputExpr.getRightExpr(), inputExpr.getLeftExpr());
- break;
-
- case GTH:
- expr = EvalTreeFactory.create(EvalNode.Type.LTH,
- inputExpr.getRightExpr(), inputExpr.getLeftExpr());
- break;
- case GEQ:
- expr = EvalTreeFactory.create(EvalNode.Type.LEQ,
- inputExpr.getRightExpr(), inputExpr.getLeftExpr());
- break;
- case LTH:
- expr = EvalTreeFactory.create(EvalNode.Type.GTH,
- inputExpr.getRightExpr(), inputExpr.getLeftExpr());
- break;
- case LEQ:
- expr = EvalTreeFactory.create(EvalNode.Type.GEQ,
- inputExpr.getRightExpr(), inputExpr.getLeftExpr());
- break;
-
- default :
- throw new AlgebraicException("Cannot commutate the expr: " + inputExpr);
- }
-
- return expr;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/BinaryEval.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/BinaryEval.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/BinaryEval.java
deleted file mode 100644
index 4d900ca..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/BinaryEval.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.engine.eval;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-import com.google.gson.Gson;
-import com.google.gson.annotations.Expose;
-import tajo.catalog.CatalogUtil;
-import tajo.catalog.Schema;
-import tajo.common.TajoDataTypes;
-import tajo.common.TajoDataTypes.DataType;
-import tajo.datum.Datum;
-import tajo.datum.DatumFactory;
-import tajo.engine.json.GsonCreator;
-import tajo.engine.utils.SchemaUtil;
-import tajo.storage.Tuple;
-
-public class BinaryEval extends EvalNode implements Cloneable {
- @Expose private DataType[] returnType = null;
-
- private class BinaryEvalCtx implements EvalContext {
- EvalContext left;
- EvalContext right;
- }
-
- /**
- * @param type
- */
- public BinaryEval(Type type, EvalNode left, EvalNode right) {
- super(type, left, right);
- Preconditions.checkNotNull(type);
- Preconditions.checkNotNull(left);
- Preconditions.checkNotNull(right);
-
- if(
- type == Type.AND ||
- type == Type.OR ||
- type == Type.EQUAL ||
- type == Type.LTH ||
- type == Type.GTH ||
- type == Type.LEQ ||
- type == Type.GEQ
- ) {
- this.returnType = CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.BOOLEAN);
- } else if (
- type == Type.PLUS ||
- type == Type.MINUS ||
- type == Type.MULTIPLY ||
- type == Type.DIVIDE ||
- type == Type.MODULAR
- ) {
- this.returnType = SchemaUtil.newNoNameSchema(determineType(left.getValueType()[0],
- right.getValueType()[0]));
- }
- }
-
- public BinaryEval(PartialBinaryExpr expr) {
- this(expr.type, expr.leftExpr, expr.rightExpr);
- }
-
- @Override
- public EvalContext newContext() {
- BinaryEvalCtx newCtx = new BinaryEvalCtx();
- newCtx.left = leftExpr.newContext();
- newCtx.right = rightExpr.newContext();
-
- return newCtx;
- }
-
- private DataType determineType(DataType left, DataType right) {
- switch (left.getType()) {
- case INT4: {
- switch(right.getType()) {
- case INT2:
- case INT4: return CatalogUtil.newDataTypeWithoutLen(TajoDataTypes.Type.INT4);
- case INT8: return CatalogUtil.newDataTypeWithoutLen(TajoDataTypes.Type.INT8);
- case FLOAT4: return CatalogUtil.newDataTypeWithoutLen(TajoDataTypes.Type.FLOAT4);
- case FLOAT8: return CatalogUtil.newDataTypeWithoutLen(TajoDataTypes.Type.FLOAT8);
- default: throw new InvalidEvalException();
- }
- }
-
- case INT8: {
- switch(right.getType()) {
- case INT2:
- case INT4:
- case INT8: return CatalogUtil.newDataTypeWithoutLen(TajoDataTypes.Type.INT8);
- case FLOAT4:
- case FLOAT8: return CatalogUtil.newDataTypeWithoutLen(TajoDataTypes.Type.FLOAT8);
- default: throw new InvalidEvalException();
- }
- }
-
- case FLOAT4: {
- switch(right.getType()) {
- case INT2:
- case INT4:
- case INT8:
- case FLOAT4:
- case FLOAT8: return CatalogUtil.newDataTypeWithoutLen(TajoDataTypes.Type.FLOAT8);
- default: throw new InvalidEvalException();
- }
- }
-
- case FLOAT8: {
- switch(right.getType()) {
- case INT2:
- case INT4:
- case INT8:
- case FLOAT4:
- case FLOAT8: return CatalogUtil.newDataTypeWithoutLen(TajoDataTypes.Type.FLOAT8);
- default: throw new InvalidEvalException();
- }
- }
-
- default: return left;
- }
- }
-
- /* (non-Javadoc)
- * @see nta.query.executor.eval.Expr#evalBool(Tuple)
- */
- @Override
- public void eval(EvalContext ctx, Schema schema, Tuple tuple) {
- BinaryEvalCtx binCtx = (BinaryEvalCtx) ctx;
- leftExpr.eval(binCtx == null ? null : binCtx.left, schema, tuple);
- rightExpr.eval(binCtx == null ? null : binCtx.right, schema, tuple);
- }
-
- @Override
- public Datum terminate(EvalContext ctx) {
- BinaryEvalCtx binCtx = (BinaryEvalCtx) ctx;
-
- switch(type) {
- case AND:
- return DatumFactory.createBool(leftExpr.terminate(binCtx.left).asBool()
- && rightExpr.terminate(binCtx.right).asBool());
- case OR:
- return DatumFactory.createBool(leftExpr.terminate(binCtx.left).asBool()
- || rightExpr.terminate(binCtx.right).asBool());
-
- case EQUAL:
- return leftExpr.terminate(binCtx.left).equalsTo(rightExpr.terminate(binCtx.right));
- case NOT_EQUAL:
- return DatumFactory.createBool(!leftExpr.terminate(binCtx.left).equalsTo(rightExpr.terminate(binCtx.right)).
- asBool());
- case LTH:
- return leftExpr.terminate(binCtx.left).lessThan(rightExpr.terminate(binCtx.right));
- case LEQ:
- return leftExpr.terminate(binCtx.left).lessThanEqual(rightExpr.terminate(binCtx.right));
- case GTH:
- return leftExpr.terminate(binCtx.left).greaterThan(rightExpr.terminate(binCtx.right));
- case GEQ:
- return leftExpr.terminate(binCtx.left).greaterThanEqual(rightExpr.terminate(binCtx.right));
-
- case PLUS:
- return leftExpr.terminate(binCtx.left).plus(rightExpr.terminate(binCtx.right));
- case MINUS:
- return leftExpr.terminate(binCtx.left).minus(rightExpr.terminate(binCtx.right));
- case MULTIPLY:
- return leftExpr.terminate(binCtx.left).multiply(rightExpr.terminate(binCtx.right));
- case DIVIDE:
- return leftExpr.terminate(binCtx.left).divide(rightExpr.terminate(binCtx.right));
- case MODULAR:
- return leftExpr.terminate(binCtx.left).modular(rightExpr.terminate(binCtx.right));
- default:
- throw new InvalidEvalException("We does not support " + type + " expression yet");
- }
- }
-
- @Override
- public String getName() {
- return "?";
- }
-
- @Override
- public DataType [] getValueType() {
- if (returnType == null) {
-
- }
- return returnType;
- }
-
- public String toString() {
- return leftExpr +" "+type+" "+rightExpr;
- }
-
- public String toJSON() {
- Gson gson = GsonCreator.getInstance();
- return gson.toJson(this, EvalNode.class);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof BinaryEval) {
- BinaryEval other = (BinaryEval) obj;
-
- boolean b1 = this.type == other.type;
- boolean b2 = leftExpr.equals(other.leftExpr);
- boolean b3 = rightExpr.equals(other.rightExpr);
- return b1 && b2 && b3;
- }
- return false;
- }
-
- public int hashCode() {
- return Objects.hashCode(this.type, leftExpr, rightExpr);
- }
-
- @Override
- public Object clone() throws CloneNotSupportedException {
- BinaryEval eval = (BinaryEval) super.clone();
- eval.returnType = returnType;
-
- return eval;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/CaseWhenEval.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/CaseWhenEval.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/CaseWhenEval.java
deleted file mode 100644
index 31a1a02..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/CaseWhenEval.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.engine.eval;
-
-import com.google.common.collect.Lists;
-import com.google.gson.annotations.Expose;
-import tajo.catalog.CatalogUtil;
-import tajo.catalog.Schema;
-import tajo.common.TajoDataTypes;
-import tajo.common.TajoDataTypes.DataType;
-import tajo.datum.Datum;
-import tajo.datum.DatumFactory;
-import tajo.storage.Tuple;
-
-import java.util.List;
-
-public class CaseWhenEval extends EvalNode {
- @Expose private List<WhenEval> whens = Lists.newArrayList();
- @Expose private EvalNode elseResult;
-
- public CaseWhenEval() {
- super(Type.CASE);
- }
-
- public void addWhen(EvalNode condition, EvalNode result) {
- whens.add(new WhenEval(condition, result));
- }
-
- public void setElseResult(EvalNode elseResult) {
- this.elseResult = elseResult;
- }
-
- @Override
- public EvalContext newContext() {
- return new CaseContext(whens, elseResult != null ? elseResult.newContext() : null);
- }
-
- @Override
- public DataType [] getValueType() {
- return whens.get(0).getResultExpr().getValueType();
- }
-
- @Override
- public String getName() {
- return "?";
- }
-
- public void eval(EvalContext ctx, Schema schema, Tuple tuple) {
- CaseContext caseCtx = (CaseContext) ctx;
- for (int i = 0; i < whens.size(); i++) {
- whens.get(i).eval(caseCtx.contexts[i], schema, tuple);
- }
-
- if (elseResult != null) { // without else clause
- elseResult.eval(caseCtx.elseCtx, schema, tuple);
- }
- }
-
- @Override
- public Datum terminate(EvalContext ctx) {
- CaseContext caseCtx = (CaseContext) ctx;
- for (int i = 0; i < whens.size(); i++) {
- if (whens.get(i).terminate(caseCtx.contexts[i]).asBool()) {
- return whens.get(i).getThenResult(caseCtx.contexts[i]);
- }
- }
- if (elseResult != null) { // without else clause
- return elseResult.terminate(caseCtx.elseCtx);
- } else {
- return DatumFactory.createNullDatum();
- }
- }
-
- public String toString() {
- StringBuilder sb = new StringBuilder("CASE\n");
- for (WhenEval when : whens) {
- sb.append(when).append("\n");
- }
-
- sb.append("ELSE ").append(elseResult).append(" END\n");
-
- return sb.toString();
- }
-
- @Override
- public void preOrder(EvalNodeVisitor visitor) {
- visitor.visit(this);
- for (WhenEval when : whens) {
- when.preOrder(visitor);
- }
- if (elseResult != null) { // without else clause
- elseResult.preOrder(visitor);
- }
- }
-
- @Override
- public void postOrder(EvalNodeVisitor visitor) {
- for (WhenEval when : whens) {
- when.postOrder(visitor);
- }
- if (elseResult != null) { // without else clause
- elseResult.postOrder(visitor);
- }
- visitor.visit(this);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof CaseWhenEval) {
- CaseWhenEval other = (CaseWhenEval) obj;
-
- for (int i = 0; i < other.whens.size(); i++) {
- if (!whens.get(i).equals(other.whens.get(i))) {
- return false;
- }
- }
- return elseResult.equals(other.elseResult);
- } else {
- return false;
- }
- }
-
- public static class WhenEval extends EvalNode {
- @Expose private EvalNode condition;
- @Expose private EvalNode result;
-
- public WhenEval(EvalNode condition, EvalNode result) {
- super(Type.WHEN);
- this.condition = condition;
- this.result = result;
- }
-
- @Override
- public EvalContext newContext() {
- return new WhenContext(condition.newContext(), result.newContext());
- }
-
- @Override
- public DataType [] getValueType() {
- return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.BOOLEAN);
- }
-
- @Override
- public String getName() {
- return "when?";
- }
-
- public void eval(EvalContext ctx, Schema schema, Tuple tuple) {
- condition.eval(((WhenContext) ctx).condCtx, schema, tuple);
- result.eval(((WhenContext) ctx).resultCtx, schema, tuple);
- }
-
- @Override
- public Datum terminate(EvalContext ctx) {
- return condition.terminate(((WhenContext) ctx).condCtx);
- }
-
- public EvalNode getConditionExpr() {
- return this.condition;
- }
-
- public EvalNode getResultExpr() {
- return this.result;
- }
-
- public String toString() {
- return "WHEN " + condition + " THEN " + result;
- }
-
- private class WhenContext implements EvalContext {
- EvalContext condCtx;
- EvalContext resultCtx;
-
- public WhenContext(EvalContext condCtx, EvalContext resultCtx) {
- this.condCtx = condCtx;
- this.resultCtx = resultCtx;
- }
- }
-
- public Datum getThenResult(EvalContext ctx) {
- return result.terminate(((WhenContext) ctx).resultCtx);
- }
-
- @Override
- public void preOrder(EvalNodeVisitor visitor) {
- visitor.visit(this);
- condition.preOrder(visitor);
- result.preOrder(visitor);
- }
-
- @Override
- public void postOrder(EvalNodeVisitor visitor) {
- condition.postOrder(visitor);
- result.postOrder(visitor);
- visitor.visit(this);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof WhenEval) {
- WhenEval other = (WhenEval) obj;
- return this.condition == other.condition
- && this.result == other.result;
- } else {
- return false;
- }
- }
- }
-
- private class CaseContext implements EvalContext {
- EvalContext [] contexts;
- EvalContext elseCtx;
-
- CaseContext(List<WhenEval> whens, EvalContext elseCtx) {
- contexts = new EvalContext[whens.size()];
- for (int i = 0; i < whens.size(); i++) {
- contexts[i] = whens.get(i).newContext();
- }
- this.elseCtx = elseCtx;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/ConstEval.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/ConstEval.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/ConstEval.java
deleted file mode 100644
index a8917bc..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/ConstEval.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.engine.eval;
-
-import com.google.common.base.Objects;
-import com.google.gson.Gson;
-import com.google.gson.annotations.Expose;
-import tajo.catalog.CatalogUtil;
-import tajo.common.TajoDataTypes;
-import tajo.common.TajoDataTypes.DataType;
-import tajo.datum.Datum;
-import tajo.engine.json.GsonCreator;
-
-public class ConstEval extends EvalNode implements Comparable<ConstEval>, Cloneable {
- @Expose Datum datum = null;
-
- public ConstEval(Datum datum) {
- super(Type.CONST);
- this.datum = datum;
- }
-
- @Override
- public EvalContext newContext() {
- return null;
- }
-
- @Override
- public Datum terminate(EvalContext ctx) {
- return this.datum;
- }
-
-
- public Datum getValue() {
- return this.datum;
- }
-
- public String toString() {
- return datum.toString();
- }
-
- public String toJSON() {
- Gson gson = GsonCreator.getInstance();
- return gson.toJson(this, EvalNode.class);
- }
-
- @Override
- public DataType [] getValueType() {
- switch(this.datum.type()) {
- case BOOLEAN: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.BOOLEAN);
- case BIT: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.BIT);
- case CHAR: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.CHAR);
- case INT1: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.INT1);
- case INT2: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.INT2);
- case INT4: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.INT4);
- case INT8: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.INT8);
- case FLOAT4: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.FLOAT4);
- case FLOAT8 : return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.FLOAT8);
- case BLOB : return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.BLOB);
- case TEXT: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.TEXT);
- case INET4: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.INET4);
- default: return CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.ANY);
- }
- }
-
- @Override
- public String getName() {
- return this.datum.toString();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof ConstEval) {
- ConstEval other = (ConstEval) obj;
-
- if (this.type == other.type && this.datum.equals(other.datum)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(type, datum.type(), datum);
- }
-
- @Override
- public Object clone() throws CloneNotSupportedException {
- ConstEval eval = (ConstEval) super.clone();
- eval.datum = datum;
-
- return eval;
- }
-
- @Override
- public int compareTo(ConstEval other) {
- return datum.compareTo(other.datum);
- }
-
- @Override
- public void preOrder(EvalNodeVisitor visitor) {
- visitor.visit(this);
- }
-
- @Override
- public void postOrder(EvalNodeVisitor visitor) {
- visitor.visit(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalContext.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalContext.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalContext.java
deleted file mode 100644
index 541e854..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalContext.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.engine.eval;
-
-public interface EvalContext {
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalNode.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalNode.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalNode.java
deleted file mode 100644
index 14664b0..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalNode.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.engine.eval;
-
-import com.google.gson.Gson;
-import com.google.gson.annotations.Expose;
-import tajo.catalog.Schema;
-import tajo.common.TajoDataTypes.DataType;
-import tajo.datum.Datum;
-import tajo.engine.json.GsonCreator;
-import tajo.storage.Tuple;
-
-public abstract class EvalNode implements Cloneable {
- @Expose
- protected Type type;
- @Expose
- protected EvalNode leftExpr;
- @Expose
- protected EvalNode rightExpr;
-
- public EvalNode(Type type) {
- this.type = type;
- }
-
- public EvalNode(Type type, EvalNode left, EvalNode right) {
- this(type);
- this.leftExpr = left;
- this.rightExpr = right;
- }
-
- public abstract EvalContext newContext();
-
- public Type getType() {
- return this.type;
- }
-
- public void setLeftExpr(EvalNode expr) {
- this.leftExpr = expr;
- }
-
- public EvalNode getLeftExpr() {
- return this.leftExpr;
- }
-
- public void setRightExpr(EvalNode expr) {
- this.rightExpr = expr;
- }
-
- public EvalNode getRightExpr() {
- return this.rightExpr;
- }
-
- public EvalNode getExpr(int id) {
- if (id == 0) {
- return this.leftExpr;
- } else if (id == 1) {
- return this.rightExpr;
- } else {
- throw new ArrayIndexOutOfBoundsException("only 0 or 1 is available (" + id + " is not available)");
- }
- }
-
- public abstract DataType [] getValueType();
-
- public abstract String getName();
-
- public String toString() {
- return "("+this.type+"("+leftExpr.toString()+" "+rightExpr.toString()+"))";
- }
-
- public String toJSON() {
- Gson gson = GsonCreator.getInstance();
- return gson.toJson(this, EvalNode.class);
- }
-
- public void eval(EvalContext ctx, Schema schema, Tuple tuple) {}
-
- public abstract Datum terminate(EvalContext ctx);
-
- public void preOrder(EvalNodeVisitor visitor) {
- visitor.visit(this);
- leftExpr.preOrder(visitor);
- rightExpr.preOrder(visitor);
- }
-
- public void postOrder(EvalNodeVisitor visitor) {
- leftExpr.postOrder(visitor);
- rightExpr.postOrder(visitor);
- visitor.visit(this);
- }
-
- public static enum Type {
- AGG_FUNCTION,
- AND,
- OR,
- EQUAL("="),
- IS,
- NOT_EQUAL("<>"),
- LTH("<"),
- LEQ("<="),
- GTH(">"),
- GEQ(">="),
- NOT("!"),
- PLUS("+"),
- MINUS("-"),
- MODULAR("%"),
- MULTIPLY("*"),
- DIVIDE("/"),
- FIELD,
- FUNCTION,
- LIKE,
- CONST,
- CASE,
- WHEN;
-
- private String represent;
- Type() {
- }
- Type(String represent) {
- this.represent = represent;
- }
-
- public String toString() {
- return represent == null ? this.name() : represent;
- }
- }
-
- public abstract boolean equals(Object obj);
-
- @Override
- public Object clone() throws CloneNotSupportedException {
- EvalNode node = (EvalNode) super.clone();
- node.type = type;
- node.leftExpr = leftExpr != null ? (EvalNode) leftExpr.clone() : null;
- node.rightExpr = rightExpr != null ? (EvalNode) rightExpr.clone() : null;
-
- return node;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalNodeVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalNodeVisitor.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalNodeVisitor.java
deleted file mode 100644
index e6f36a6..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalNodeVisitor.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.engine.eval;
-
-public interface EvalNodeVisitor {
- public void visit(EvalNode node);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalTreeFactory.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalTreeFactory.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalTreeFactory.java
deleted file mode 100644
index 9face87..0000000
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/eval/EvalTreeFactory.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tajo.engine.eval;
-
-import tajo.datum.Datum;
-
-public class EvalTreeFactory {
- public static ConstEval newConst(Datum datum) {
- return new ConstEval(datum);
- }
-
- public static BinaryEval create(EvalNode.Type type, EvalNode e1,
- EvalNode e2) {
- return new BinaryEval(type, e1, e2);
- }
-}