tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [54/57] [abbrv] tajo git commit: TAJO-1537: Implement a virtual table for sessions. (Contributed by Yongjin Choi, Committed by Hyunsik Choi)
Date Mon, 25 May 2015 14:36:47 GMT
TAJO-1537: Implement a virtual table for sessions. (Contributed by Yongjin Choi, Committed
by Hyunsik Choi)

Closes #523, #576


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/52641569
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/52641569
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/52641569

Branch: refs/heads/index_support
Commit: 52641569e10207e4e2001467060f80ab34119744
Parents: d261234
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Mon May 18 21:47:39 2015 -0700
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Mon May 18 21:50:15 2015 -0700

----------------------------------------------------------------------
 CHANGES                                         |  3 ++
 .../InfoSchemaMetadataDictionary.java           |  2 +
 .../dictionary/SessionTableDescriptor.java      | 45 ++++++++++++++++++++
 .../NonForwardQueryResultSystemScanner.java     | 32 +++++++++++++-
 .../org/apache/tajo/session/SessionManager.java |  2 +
 .../tajo/engine/query/TestSelectQuery.java      |  7 +++
 .../TestNonForwardQueryResultSystemScanner.java |  1 +
 .../testSelectOnSessionTable.sql                |  1 +
 .../testSelectOnSessionTable.result             |  3 ++
 9 files changed, 95 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/52641569/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index dee6f14..4b20b33 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,9 @@ Release 0.11.0 - unreleased
 
   NEW FEATURES
 
+    TAJO-1537: Implement a virtual table for sessions. 
+    (Contributed by Yongjin Choi, Committed by hyunsik)
+
     TAJO-1562: Python UDAF support. (jihoon)
 
     TAJO-1344: Python UDF support. (jihoon)

http://git-wip-us.apache.org/repos/asf/tajo/blob/52641569/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
index 1bb8bc5..8312e0e 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
@@ -42,6 +42,7 @@ public class InfoSchemaMetadataDictionary {
     PARTITIONS,
     PARTITION_KEYS,
     CLUSTER,
+    SESSION,
     MAX_TABLE;
   }
   
@@ -63,6 +64,7 @@ public class InfoSchemaMetadataDictionary {
     schemaInfoTableDescriptors.set(DEFINED_TABLES.PARTITIONS.ordinal(), new PartitionsTableDescriptor(this));
     schemaInfoTableDescriptors.set(DEFINED_TABLES.PARTITION_KEYS.ordinal(), new PartitionKeysTableDescriptor(this));
     schemaInfoTableDescriptors.set(DEFINED_TABLES.CLUSTER.ordinal(), new ClusterTableDescriptor(this));
+    schemaInfoTableDescriptors.set(DEFINED_TABLES.SESSION.ordinal(), new SessionTableDescriptor(this));
   }
 
   public boolean isSystemDatabase(String databaseName) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/52641569/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/SessionTableDescriptor.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/SessionTableDescriptor.java
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/SessionTableDescriptor.java
new file mode 100644
index 0000000..935f72d
--- /dev/null
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/SessionTableDescriptor.java
@@ -0,0 +1,45 @@
+/**
+ * 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 org.apache.tajo.catalog.dictionary;
+
+import org.apache.tajo.common.TajoDataTypes.Type;
+
+class SessionTableDescriptor extends AbstractTableDescriptor {
+
+    private static final String TABLENAME = "session";
+    private final ColumnDescriptor[] columns =
+        new ColumnDescriptor[] {
+            new ColumnDescriptor("name", Type.TEXT, 0), new ColumnDescriptor("value", Type.TEXT,
0)
+        };
+
+    public SessionTableDescriptor(InfoSchemaMetadataDictionary metadataDictionary) {
+        super(metadataDictionary);
+    }
+
+    @Override
+    public String getTableNameString() {
+        return TABLENAME;
+    }
+
+    @Override
+    protected ColumnDescriptor[] getColumnDescriptors() {
+        return columns;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/52641569/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
b/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
index 6ae9677..6c1399e 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
@@ -18,10 +18,12 @@
 
 package org.apache.tajo.master.exec;
 
+import com.google.common.collect.Lists;
 import com.google.protobuf.ByteString;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.tajo.QueryId;
+import org.apache.tajo.SessionVars;
 import org.apache.tajo.TaskAttemptId;
 import org.apache.tajo.TaskId;
 import org.apache.tajo.catalog.*;
@@ -49,6 +51,8 @@ import org.apache.tajo.plan.expr.EvalNode;
 import org.apache.tajo.plan.logical.IndexScanNode;
 import org.apache.tajo.plan.logical.LogicalNode;
 import org.apache.tajo.plan.logical.ScanNode;
+import org.apache.tajo.session.InvalidSessionException;
+import org.apache.tajo.session.Session;
 import org.apache.tajo.storage.RowStoreUtil;
 import org.apache.tajo.storage.RowStoreUtil.RowStoreEncoder;
 import org.apache.tajo.storage.Tuple;
@@ -541,6 +545,25 @@ public class NonForwardQueryResultSystemScanner implements NonForwardQueryResult
     
     return tuples;
   }
+
+  private List<Tuple> getSessionInfo(Schema outSchema) {
+    List<Tuple> outputs = Lists.newArrayList();
+    Tuple eachVariable;
+
+    try {
+      for (Map.Entry<String, String> var: masterContext.getSessionManager().getAllVariables(sessionId).entrySet())
{
+        eachVariable = new VTuple(outSchema.size());
+        eachVariable.put(0, DatumFactory.createText(var.getKey()));
+        eachVariable.put(1, DatumFactory.createText(var.getValue()));
+
+        outputs.add(eachVariable);
+      }
+    } catch (InvalidSessionException e) {
+      LOG.error(e);
+    }
+
+    return outputs;
+  }
   
   private List<Tuple> fetchSystemTable(TableDesc tableDesc, Schema inSchema) {
     List<Tuple> tuples = null;
@@ -564,6 +587,8 @@ public class NonForwardQueryResultSystemScanner implements NonForwardQueryResult
       tuples = getAllPartitions(inSchema);
     } else if ("cluster".equalsIgnoreCase(tableName)) {
       tuples = getClusterInfo(inSchema);
+    } else if ("session".equalsIgnoreCase(tableName)) {
+      tuples = getSessionInfo(inSchema);
     }
     
     return tuples;    
@@ -657,7 +682,12 @@ public class NonForwardQueryResultSystemScanner implements NonForwardQueryResult
     public SystemPhysicalExec(TaskAttemptContext context, ScanNode scanNode) {
       super(context, scanNode.getInSchema(), scanNode.getOutSchema());
       this.scanNode = scanNode;
-      this.qual = this.scanNode.getQual();
+
+      if (this.scanNode.hasQual()) {
+        this.qual = this.scanNode.getQual();
+        this.qual.bind(null, inSchema);
+      }
+
       cachedData = TUtil.newList();
       currentRow = 0;
       isClosed = false;

http://git-wip-us.apache.org/repos/asf/tajo/blob/52641569/tajo-core/src/main/java/org/apache/tajo/session/SessionManager.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/session/SessionManager.java b/tajo-core/src/main/java/org/apache/tajo/session/SessionManager.java
index 5d66b2b..9c49fe1 100644
--- a/tajo-core/src/main/java/org/apache/tajo/session/SessionManager.java
+++ b/tajo-core/src/main/java/org/apache/tajo/session/SessionManager.java
@@ -25,6 +25,8 @@ import org.apache.hadoop.service.CompositeService;
 import org.apache.hadoop.yarn.event.Dispatcher;
 import org.apache.hadoop.yarn.event.EventHandler;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;

http://git-wip-us.apache.org/repos/asf/tajo/blob/52641569/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
index c0cf4d9..1351505 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
@@ -741,4 +741,11 @@ public class TestSelectQuery extends QueryTestCaseBase {
     assertResultSet(res);
     cleanupQuery(res);
   }
+
+  @Test
+  public void testSelectOnSessionTable() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/52641569/tajo-core/src/test/java/org/apache/tajo/master/TestNonForwardQueryResultSystemScanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/master/TestNonForwardQueryResultSystemScanner.java
b/tajo-core/src/test/java/org/apache/tajo/master/TestNonForwardQueryResultSystemScanner.java
index 01d4ec4..fb149b2 100644
--- a/tajo-core/src/test/java/org/apache/tajo/master/TestNonForwardQueryResultSystemScanner.java
+++ b/tajo-core/src/test/java/org/apache/tajo/master/TestNonForwardQueryResultSystemScanner.java
@@ -34,6 +34,7 @@ import org.apache.tajo.TajoTestingCluster;
 import org.apache.tajo.algebra.Expr;
 import org.apache.tajo.benchmark.TPCH;
 import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.client.TajoClient;
 import org.apache.tajo.common.TajoDataTypes.Type;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.datum.Datum;

http://git-wip-us.apache.org/repos/asf/tajo/blob/52641569/tajo-core/src/test/resources/queries/TestSelectQuery/testSelectOnSessionTable.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestSelectQuery/testSelectOnSessionTable.sql
b/tajo-core/src/test/resources/queries/TestSelectQuery/testSelectOnSessionTable.sql
new file mode 100644
index 0000000..a953751
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestSelectQuery/testSelectOnSessionTable.sql
@@ -0,0 +1 @@
+select * from information_schema.session where name = 'CURRENT_DATABASE';
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/52641569/tajo-core/src/test/resources/results/TestSelectQuery/testSelectOnSessionTable.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestSelectQuery/testSelectOnSessionTable.result
b/tajo-core/src/test/resources/results/TestSelectQuery/testSelectOnSessionTable.result
new file mode 100644
index 0000000..b8797ba
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestSelectQuery/testSelectOnSessionTable.result
@@ -0,0 +1,3 @@
+name,value
+-------------------------------
+CURRENT_DATABASE,default
\ No newline at end of file


Mime
View raw message