tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [29/39] tajo git commit: Add JdbcFragment and its protobuf definition.
Date Wed, 02 Sep 2015 11:06:52 GMT
Add JdbcFragment and its protobuf definition.


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

Branch: refs/heads/TAJO-1730
Commit: 8b76167e8945e9048138f72b1646117599d97108
Parents: 177291d
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Sat Aug 22 01:07:11 2015 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Sat Aug 22 01:07:11 2015 +0900

----------------------------------------------------------------------
 .../apache/tajo/storage/jdbc/JdbcFragment.java  | 51 ++++++++++++++++++--
 .../tajo/storage/jdbc/JdbcTablespace.java       |  9 +---
 .../src/main/proto/JdbcFragmentProtos.proto     |  2 +
 .../storage/mysql/TestMysqlJdbcTableSpace.java  |  1 +
 4 files changed, 53 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/8b76167e/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcFragment.java
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcFragment.java
b/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcFragment.java
index 960267a..2fc42b7 100644
--- a/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcFragment.java
+++ b/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcFragment.java
@@ -18,14 +18,43 @@
 
 package org.apache.tajo.storage.jdbc;
 
+import com.google.protobuf.ByteString;
+import com.google.protobuf.InvalidProtocolBufferException;
+import org.apache.tajo.BuiltinStorages;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.storage.fragment.Fragment;
+import org.apache.tajo.storage.jdbc.JdbcFragmentProtos.JdbcFragmentProto;
+import org.apache.tajo.util.TUtil;
 
-public class JdbcFragment implements Fragment, Cloneable {
+public class JdbcFragment implements Fragment, Comparable<JdbcFragment>, Cloneable
{
+  String uri;
   String inputSourceId;
-
   String [] hostNames;
 
+
+  public JdbcFragment(ByteString raw) throws InvalidProtocolBufferException {
+    JdbcFragmentProto.Builder builder = JdbcFragmentProto.newBuilder();
+    builder.mergeFrom(raw);
+    builder.build();
+    init(builder.build());
+  }
+
+  public JdbcFragment(String inputSourceId, String uri) {
+    this.inputSourceId = inputSourceId;
+    this.uri = uri;
+    this.hostNames = extractHosts(uri);
+  }
+
+  private void init(JdbcFragmentProto proto) {
+    this.uri = proto.getUri();
+    this.inputSourceId = proto.getInputSourceId();
+    this.hostNames = proto.getHostsList().toArray(new String [proto.getHostsCount()]);
+  }
+
+  private String [] extractHosts(String uri) {
+    return new String [] {};
+  }
+
   @Override
   public String getTableName() {
     return inputSourceId;
@@ -33,7 +62,18 @@ public class JdbcFragment implements Fragment, Cloneable {
 
   @Override
   public CatalogProtos.FragmentProto getProto() {
-    return null;
+    JdbcFragmentProto.Builder builder = JdbcFragmentProto.newBuilder();
+    builder.setInputSourceId(this.inputSourceId);
+    builder.setUri(this.uri);
+    if(hostNames != null) {
+      builder.addAllHosts(TUtil.newList(hostNames));
+    }
+
+    CatalogProtos.FragmentProto.Builder fragmentBuilder = CatalogProtos.FragmentProto.newBuilder();
+    fragmentBuilder.setId(this.inputSourceId);
+    fragmentBuilder.setStoreType(BuiltinStorages.TEXT);
+    fragmentBuilder.setContents(builder.buildPartial().toByteString());
+    return fragmentBuilder.build();
   }
 
   @Override
@@ -55,4 +95,9 @@ public class JdbcFragment implements Fragment, Cloneable {
   public boolean isEmpty() {
     return false;
   }
+
+  @Override
+  public int compareTo(JdbcFragment o) {
+    return this.uri.compareTo(o.uri);
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/8b76167e/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcTablespace.java
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcTablespace.java
b/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcTablespace.java
index f66c5dc..04709b0 100644
--- a/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcTablespace.java
+++ b/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/JdbcTablespace.java
@@ -18,6 +18,7 @@
 
 package org.apache.tajo.storage.jdbc;
 
+import com.google.common.collect.Lists;
 import net.minidev.json.JSONObject;
 import org.apache.hadoop.fs.Path;
 import org.apache.tajo.ExecutionBlockId;
@@ -29,7 +30,6 @@ import org.apache.tajo.exception.UnsupportedException;
 import org.apache.tajo.plan.LogicalPlan;
 import org.apache.tajo.plan.expr.EvalNode;
 import org.apache.tajo.plan.logical.LogicalNode;
-import org.apache.tajo.plan.logical.ScanNode;
 import org.apache.tajo.storage.FormatProperty;
 import org.apache.tajo.storage.StorageProperty;
 import org.apache.tajo.storage.Tablespace;
@@ -75,12 +75,7 @@ public abstract class JdbcTablespace extends Tablespace {
   public List<Fragment> getSplits(String inputSourceId,
                                   TableDesc tableDesc,
                                   @Nullable EvalNode filterCondition) throws IOException
{
-    return null;
-  }
-
-  @Override
-  public List<Fragment> getNonForwardSplit(TableDesc tableDesc, int currentPage, int
numFragments) throws IOException {
-    return null;
+    return Lists.newArrayList((Fragment)new JdbcFragment(inputSourceId, tableDesc.getUri().toASCIIString()));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/tajo/blob/8b76167e/tajo-storage/tajo-storage-jdbc/src/main/proto/JdbcFragmentProtos.proto
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-jdbc/src/main/proto/JdbcFragmentProtos.proto b/tajo-storage/tajo-storage-jdbc/src/main/proto/JdbcFragmentProtos.proto
index a09c8f1..f642e07 100644
--- a/tajo-storage/tajo-storage-jdbc/src/main/proto/JdbcFragmentProtos.proto
+++ b/tajo-storage/tajo-storage-jdbc/src/main/proto/JdbcFragmentProtos.proto
@@ -26,4 +26,6 @@ import "CatalogProtos.proto";
 
 message JdbcFragmentProto {
   required string uri = 1;
+  required string input_source_id = 2;
+  repeated string hosts = 3;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/8b76167e/tajo-storage/tajo-storage-mysql/src/test/java/org/apache/tajo/storage/mysql/TestMysqlJdbcTableSpace.java
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-mysql/src/test/java/org/apache/tajo/storage/mysql/TestMysqlJdbcTableSpace.java
b/tajo-storage/tajo-storage-mysql/src/test/java/org/apache/tajo/storage/mysql/TestMysqlJdbcTableSpace.java
index df377b6..6d2ad1b 100644
--- a/tajo-storage/tajo-storage-mysql/src/test/java/org/apache/tajo/storage/mysql/TestMysqlJdbcTableSpace.java
+++ b/tajo-storage/tajo-storage-mysql/src/test/java/org/apache/tajo/storage/mysql/TestMysqlJdbcTableSpace.java
@@ -20,6 +20,7 @@ package org.apache.tajo.storage.mysql;
 
 import com.google.common.collect.ImmutableSet;
 import io.airlift.testing.mysql.TestingMySqlServer;
+import org.apache.tajo.QueryTestCaseBase;
 import org.apache.tajo.storage.TablespaceManager;
 import org.junit.BeforeClass;
 import org.junit.Test;


Mime
View raw message