phoenix git commit: Code refine

2016-10-03 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite 17888a272 -> 1193e5afe


Code refine


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

Branch: refs/heads/calcite
Commit: 1193e5afe6dae631d107c605616e4f78df1600bf
Parents: 17888a2
Author: maryannxue 
Authored: Mon Oct 3 12:01:56 2016 -0700
Committer: maryannxue 
Committed: Mon Oct 3 12:01:56 2016 -0700

--
 .../apache/phoenix/calcite/CalciteUtils.java| 31 ++--
 .../apache/phoenix/calcite/PhoenixTable.java| 25 ++--
 2 files changed, 32 insertions(+), 24 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1193e5af/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
index df348c9..ae143f7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
@@ -21,6 +21,7 @@ import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.calcite.rel.core.Project;
 import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.rex.RexCall;
 import org.apache.calcite.rex.RexCorrelVariable;
 import org.apache.calcite.rex.RexDynamicParam;
@@ -144,7 +145,7 @@ public class CalciteUtils {
 }
 
 @SuppressWarnings("rawtypes")
-public static PDataType relDataTypeToPDataType(RelDataType relDataType) {
+public static PDataType relDataTypeToPDataType(final RelDataType 
relDataType) {
 SqlTypeName sqlTypeName = relDataType.getSqlTypeName();
 final boolean isArrayType = sqlTypeName == SqlTypeName.ARRAY;
 if (isArrayType) {
@@ -161,7 +162,33 @@ public class CalciteUtils {
 }
 return PDataType.fromTypeId(ordinal + (isArrayType ? 
PDataType.ARRAY_TYPE_BASE : 0));
 }
-
+
+@SuppressWarnings("rawtypes")
+public static RelDataType pDataTypeToRelDataType(
+final RelDataTypeFactory typeFactory, final PDataType pDataType,
+final Integer maxLength, final Integer scale, final Integer 
arraySize) {
+final boolean isArrayType = pDataType.isArrayType();
+final PDataType baseType = isArrayType ?
+PDataType.fromTypeId(pDataType.getSqlType() - 
PDataType.ARRAY_TYPE_BASE) 
+  : pDataType;
+final int sqlTypeId = baseType.getResultSetSqlType();
+final PDataType normalizedBaseType = PDataType.fromTypeId(sqlTypeId);
+final SqlTypeName sqlTypeName = 
SqlTypeName.valueOf(normalizedBaseType.getSqlTypeName());
+RelDataType type;
+if (maxLength != null && scale != null) {
+type = typeFactory.createSqlType(sqlTypeName, maxLength, scale);
+} else if (maxLength != null) {
+type = typeFactory.createSqlType(sqlTypeName, maxLength);
+} else {
+type = typeFactory.createSqlType(sqlTypeName);
+}
+if (isArrayType) {
+type = typeFactory.createArrayType(type, arraySize == null ? -1 : 
arraySize);
+}
+
+return type;
+}
+
 public static JoinType convertJoinType(JoinRelType type) {
 JoinType ret = null;
 switch (type) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1193e5af/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
index 905441f..fb9f9c0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
@@ -124,34 +124,15 @@ public class PhoenixTable extends AbstractTable 
implements TranslatableTable {
 return tableMapping.getMappedColumns();
 }
 
-@SuppressWarnings("rawtypes")
 @Override
 public RelDataType getRowType(RelDataTypeFactory typeFactory) {
 final RelDataTypeFactory.FieldInfoBuilder builder = 
typeFactory.builder();
 final List columns = tableMapping.getMappedColumns();
 for (int i = 0; i < columns.size(); i++) {
 PColumn pColumn = columns.get(i);
-final 

phoenix git commit: Code refine for PhoenixSchema

2015-04-30 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite 8e3f68a2d - 1ee1f2011


Code refine for PhoenixSchema


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

Branch: refs/heads/calcite
Commit: 1ee1f2011eda8a3b22c855e7730ed74b1bd628a9
Parents: 8e3f68a
Author: maryannxue wei@intel.com
Authored: Thu Apr 30 16:45:13 2015 -0400
Committer: maryannxue wei@intel.com
Committed: Thu Apr 30 16:45:13 2015 -0400

--
 .../apache/phoenix/calcite/PhoenixSchema.java   | 22 +++-
 1 file changed, 12 insertions(+), 10 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1ee1f201/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
index 816c156..589f61d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
@@ -40,34 +40,36 @@ public class PhoenixSchema implements Schema {
 this.schemaName = name;
 this.pc = pc;
 this.client = new MetaDataClient(pc);
-this.subSchemaNames = Sets.newHashSet();
-this.tableNames = Sets.newHashSet();
-if (schemaName == null) {
-loadSubSchemaNames();
-}
-loadTableNames();
+this.subSchemaNames = name == null ? 
+  ImmutableSet.String copyOf(loadSubSchemaNames()) 
+: Collections.String emptySet();
+this.tableNames = ImmutableSet.String copyOf(loadTableNames());
 }
 
-private void loadSubSchemaNames() {
+private SetString loadSubSchemaNames() {
 try {
 DatabaseMetaData md = pc.getMetaData();
 ResultSet rs = md.getSchemas();
+SetString subSchemaNames = Sets.newHashSet();
 while (rs.next()) {
 String schemaName = 
rs.getString(PhoenixDatabaseMetaData.TABLE_SCHEM);
-this.subSchemaNames.add(schemaName == null ?  : schemaName);
+subSchemaNames.add(schemaName == null ?  : schemaName);
 }
+return subSchemaNames;
 } catch (SQLException e) {
 throw new RuntimeException(e);
 }
 }
 
-private void loadTableNames() {
+private SetString loadTableNames() {
 try {
 DatabaseMetaData md = pc.getMetaData();
 ResultSet rs = md.getTables(null, schemaName == null ?  : 
schemaName, null, null);
+SetString tableNames = Sets.newHashSet();
 while (rs.next()) {
-
this.tableNames.add(rs.getString(PhoenixDatabaseMetaData.TABLE_NAME));
+
tableNames.add(rs.getString(PhoenixDatabaseMetaData.TABLE_NAME));
 }
+return tableNames;
 } catch (SQLException e) {
 throw new RuntimeException(e);
 }