You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ar...@apache.org on 2018/07/25 19:28:19 UTC

[08/10] impala git commit: IMPALA-7257. Support Kudu tables in LocalCatalog

IMPALA-7257. Support Kudu tables in LocalCatalog

This adds support for querying Kudu tables when --use_local_catalog is
enabled.

With this change, most of the kudu e2e tests pass. Those that don't are
related to missing support for CREATE TABLE AS SELECT, which currently
has some downcasts to 'Db' causing issues. That will be addressed in a
separate patch along with fixing CTAS for FS-backed tables.

Change-Id: I5b6a317ee895e43e00ade953e814867b56b4e6dd
Reviewed-on: http://gerrit.cloudera.org:8080/10912
Tested-by: Impala Public Jenkins <im...@cloudera.com>
Reviewed-by: Tianyi Wang <tw...@cloudera.com>


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

Branch: refs/heads/master
Commit: c333b55260bb5183fbf8e112cc1b3864bd7b383b
Parents: def5c88
Author: Todd Lipcon <to...@cloudera.com>
Authored: Fri Jun 29 15:35:29 2018 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Wed Jul 25 19:27:26 2018 +0000

----------------------------------------------------------------------
 .../AlterTableAddDropRangePartitionStmt.java    |   8 +-
 .../analysis/AlterTableAddPartitionStmt.java    |   3 +-
 .../analysis/AlterTableAddReplaceColsStmt.java  |   4 +-
 .../impala/analysis/AlterTableAlterColStmt.java |   6 +-
 .../analysis/AlterTableDropPartitionStmt.java   |   4 +-
 .../analysis/AlterTableSetFileFormatStmt.java   |   4 +-
 .../analysis/AlterTableSetLocationStmt.java     |   4 +-
 .../analysis/AlterTableSetTblProperties.java    |   5 +-
 .../impala/analysis/AlterTableSortByStmt.java   |   4 +-
 .../org/apache/impala/analysis/Analyzer.java    |   5 +-
 .../analysis/CreateTableAsSelectStmt.java       |   3 +-
 .../org/apache/impala/analysis/InsertStmt.java  |  31 ++-
 .../impala/analysis/KuduPartitionExpr.java      |   9 +-
 .../org/apache/impala/analysis/ModifyStmt.java  |  10 +-
 .../apache/impala/analysis/ShowStatsStmt.java   |   8 +-
 .../org/apache/impala/analysis/ToSqlUtils.java  |   5 +-
 .../apache/impala/analysis/TupleDescriptor.java |   4 +-
 .../org/apache/impala/catalog/FeKuduTable.java  | 221 +++++++++++++++++++
 .../org/apache/impala/catalog/KuduTable.java    | 188 ++--------------
 .../impala/catalog/local/LocalCatalog.java      |  11 +-
 .../impala/catalog/local/LocalFsTable.java      |  20 +-
 .../impala/catalog/local/LocalKuduTable.java    | 202 +++++++++++++++++
 .../apache/impala/catalog/local/LocalTable.java | 189 +++++++++-------
 .../apache/impala/catalog/local/LocalView.java  |   5 +-
 .../impala/planner/DistributedPlanner.java      |   8 +-
 .../org/apache/impala/planner/KuduScanNode.java |   6 +-
 .../java/org/apache/impala/planner/Planner.java |   6 +-
 .../impala/planner/SingleNodePlanner.java       |   4 +-
 .../org/apache/impala/planner/TableSink.java    |   4 +-
 .../org/apache/impala/service/Frontend.java     |  12 +-
 .../impala/service/KuduCatalogOpExecutor.java   |   4 +-
 .../java/org/apache/impala/util/KuduUtil.java   |   6 +-
 .../impala/catalog/local/LocalCatalogTest.java  |  37 +++-
 33 files changed, 697 insertions(+), 343 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/AlterTableAddDropRangePartitionStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableAddDropRangePartitionStmt.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableAddDropRangePartitionStmt.java
index 6c62df5..44c7091 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableAddDropRangePartitionStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableAddDropRangePartitionStmt.java
@@ -20,8 +20,8 @@ package org.apache.impala.analysis;
 import java.util.List;
 
 import org.apache.impala.catalog.Column;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.thrift.TAlterTableAddDropRangePartitionParams;
 import org.apache.impala.thrift.TAlterTableParams;
@@ -88,12 +88,12 @@ public class AlterTableAddDropRangePartitionStmt extends AlterTableStmt {
   public void analyze(Analyzer analyzer) throws AnalysisException {
     super.analyze(analyzer);
     FeTable table = getTargetTable();
-    if (!(table instanceof KuduTable)) {
+    if (!(table instanceof FeKuduTable)) {
       throw new AnalysisException(String.format("Table %s does not support range " +
           "partitions: RANGE %s", table.getFullName(), rangePartitionSpec_.toSql()));
     }
-    KuduTable kuduTable = (KuduTable) table;
-    List<String> colNames = kuduTable.getRangePartitioningColNames();
+    FeKuduTable kuduTable = (FeKuduTable) table;
+    List<String> colNames = FeKuduTable.Utils.getRangePartitioningColNames(kuduTable);
     if (colNames.isEmpty()) {
       throw new AnalysisException(String.format("Cannot add/drop partition %s: " +
           "Kudu table %s doesn't have a range-based partitioning.",

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/AlterTableAddPartitionStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableAddPartitionStmt.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableAddPartitionStmt.java
index 9c1a035..4b2356a 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableAddPartitionStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableAddPartitionStmt.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Joiner;
 import com.google.common.collect.Sets;
 
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.AnalysisException;
@@ -84,7 +85,7 @@ public class AlterTableAddPartitionStmt extends AlterTableStmt {
   public void analyze(Analyzer analyzer) throws AnalysisException {
     super.analyze(analyzer);
     FeTable table = getTargetTable();
-    if (table instanceof KuduTable) {
+    if (table instanceof FeKuduTable) {
       throw new AnalysisException("ALTER TABLE ADD PARTITION is not supported for " +
           "Kudu tables: " + table.getTableName());
     }

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/AlterTableAddReplaceColsStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableAddReplaceColsStmt.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableAddReplaceColsStmt.java
index d00c0cd..6abac52 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableAddReplaceColsStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableAddReplaceColsStmt.java
@@ -23,9 +23,9 @@ import java.util.Set;
 import org.apache.hadoop.hive.metastore.api.FieldSchema;
 
 import org.apache.impala.catalog.Column;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HBaseTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.thrift.TAlterTableAddReplaceColsParams;
 import org.apache.impala.thrift.TAlterTableParams;
@@ -80,7 +80,7 @@ public class AlterTableAddReplaceColsStmt extends AlterTableStmt {
           "supported on HBase tables.");
     }
 
-    boolean isKuduTable = t instanceof KuduTable;
+    boolean isKuduTable = t instanceof FeKuduTable;
     if (isKuduTable && replaceExistingCols_) {
       throw new AnalysisException("ALTER TABLE REPLACE COLUMNS is not " +
           "supported on Kudu tables.");

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/AlterTableAlterColStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableAlterColStmt.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableAlterColStmt.java
index e6b0d49..f7d8ce8 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableAlterColStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableAlterColStmt.java
@@ -20,10 +20,10 @@ package org.apache.impala.analysis;
 import java.util.Map;
 
 import org.apache.impala.catalog.Column;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HBaseTable;
 import org.apache.impala.catalog.KuduColumn;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.thrift.TAlterTableAlterColParams;
 import org.apache.impala.thrift.TAlterTableParams;
@@ -134,7 +134,7 @@ public class AlterTableAlterColStmt extends AlterTableStmt {
     }
     if (newColDef_.hasKuduOptions()) {
       // Disallow Kudu options on non-Kudu tables.
-      if (!(t instanceof KuduTable)) {
+      if (!(t instanceof FeKuduTable)) {
         if (isDropDefault_) {
           throw new AnalysisException(String.format(
               "Unsupported column option for non-Kudu table: DROP DEFAULT"));
@@ -153,7 +153,7 @@ public class AlterTableAlterColStmt extends AlterTableStmt {
                 newColDef_.toString()));
       }
     }
-    if (t instanceof KuduTable) {
+    if (t instanceof FeKuduTable) {
       KuduColumn col = (KuduColumn) t.getColumn(colName_);
       if (!col.getType().equals(newColDef_.getType())) {
         throw new AnalysisException(String.format("Cannot change the type of a Kudu " +

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/AlterTableDropPartitionStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableDropPartitionStmt.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableDropPartitionStmt.java
index 048b985..707f3de 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableDropPartitionStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableDropPartitionStmt.java
@@ -18,8 +18,8 @@
 package org.apache.impala.analysis;
 
 import org.apache.impala.authorization.Privilege;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.thrift.TAlterTableDropPartitionParams;
 import org.apache.impala.thrift.TAlterTableParams;
@@ -75,7 +75,7 @@ public class AlterTableDropPartitionStmt extends AlterTableStmt {
   public void analyze(Analyzer analyzer) throws AnalysisException {
     super.analyze(analyzer);
     FeTable table = getTargetTable();
-    if (table instanceof KuduTable) {
+    if (table instanceof FeKuduTable) {
       throw new AnalysisException("ALTER TABLE DROP PARTITION is not supported for " +
           "Kudu tables: " + partitionSet_.toSql());
     }

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/AlterTableSetFileFormatStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableSetFileFormatStmt.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableSetFileFormatStmt.java
index 31c046a..b88216c 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableSetFileFormatStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableSetFileFormatStmt.java
@@ -17,8 +17,8 @@
 
 package org.apache.impala.analysis;
 
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.thrift.TAlterTableParams;
 import org.apache.impala.thrift.TAlterTableSetFileFormatParams;
@@ -56,7 +56,7 @@ public class AlterTableSetFileFormatStmt extends AlterTableSetStmt {
   public void analyze(Analyzer analyzer) throws AnalysisException {
     super.analyze(analyzer);
     FeTable tbl = getTargetTable();
-    if (tbl instanceof KuduTable) {
+    if (tbl instanceof FeKuduTable) {
       throw new AnalysisException("ALTER TABLE SET FILEFORMAT is not supported " +
           "on Kudu tables: " + tbl.getFullName());
     }

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/AlterTableSetLocationStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableSetLocationStmt.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableSetLocationStmt.java
index db8a804..b034ab5 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableSetLocationStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableSetLocationStmt.java
@@ -23,10 +23,10 @@ import java.util.List;
 import org.apache.hadoop.fs.permission.FsAction;
 import org.apache.impala.authorization.Privilege;
 import org.apache.impala.catalog.FeFsPartition;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HdfsPartition;
 import org.apache.impala.catalog.HdfsTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.thrift.TAlterTableParams;
 import org.apache.impala.thrift.TAlterTableSetLocationParams;
@@ -111,7 +111,7 @@ public class AlterTableSetLocationStmt extends AlterTableSetStmt {
             "uncache before changing the location using: ALTER TABLE %s SET UNCACHED",
             table.getFullName()));
       }
-    } else if (table instanceof KuduTable) {
+    } else if (table instanceof FeKuduTable) {
       throw new AnalysisException("ALTER TABLE SET LOCATION is not supported on Kudu " +
           "tables: " + table.getFullName());
     }

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/AlterTableSetTblProperties.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableSetTblProperties.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableSetTblProperties.java
index 26c5ac0..1f02390 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableSetTblProperties.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableSetTblProperties.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.hive.serde2.avro.AvroSerdeUtils;
 import org.apache.impala.authorization.PrivilegeRequestBuilder;
 import org.apache.impala.catalog.Column;
 import org.apache.impala.catalog.FeFsTable;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HBaseTable;
 import org.apache.impala.catalog.HdfsTable;
@@ -93,7 +94,7 @@ public class AlterTableSetTblProperties extends AlterTableSetStmt {
           hive_metastoreConstants.META_TABLE_STORAGE));
     }
 
-    if (getTargetTable() instanceof KuduTable) analyzeKuduTable(analyzer);
+    if (getTargetTable() instanceof FeKuduTable) analyzeKuduTable(analyzer);
 
     // Check avro schema when it is set in avro.schema.url or avro.schema.literal to
     // avoid potential metadata corruption (see IMPALA-2042).
@@ -211,7 +212,7 @@ public class AlterTableSetTblProperties extends AlterTableSetStmt {
     // AlterTableSetStmt::analyze().
     Preconditions.checkState(!(table instanceof HBaseTable));
 
-    if (table instanceof KuduTable) {
+    if (table instanceof FeKuduTable) {
       throw new AnalysisException(String.format("'%s' table property is not supported " +
           "for Kudu tables.", AlterTableSortByStmt.TBL_PROP_SORT_COLUMNS));
     }

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/AlterTableSortByStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableSortByStmt.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableSortByStmt.java
index 2b54b74..0f99c9b 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableSortByStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableSortByStmt.java
@@ -20,9 +20,9 @@ package org.apache.impala.analysis;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HBaseTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.thrift.TAlterTableParams;
 import org.apache.impala.thrift.TAlterTableSetTblPropertiesParams;
@@ -71,7 +71,7 @@ public class AlterTableSortByStmt extends AlterTableStmt {
     if (targetTable instanceof HBaseTable) {
       throw new AnalysisException("ALTER TABLE SORT BY not supported on HBase tables.");
     }
-    if (targetTable instanceof KuduTable) {
+    if (targetTable instanceof FeKuduTable) {
       throw new AnalysisException("ALTER TABLE SORT BY not supported on Kudu tables.");
     }
 

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/Analyzer.java b/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
index 1a4ea13..e902383 100644
--- a/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
+++ b/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
@@ -38,17 +38,16 @@ import org.apache.impala.authorization.PrivilegeRequest;
 import org.apache.impala.authorization.PrivilegeRequestBuilder;
 import org.apache.impala.authorization.User;
 import org.apache.impala.catalog.Column;
-import org.apache.impala.catalog.DataSourceTable;
 import org.apache.impala.catalog.DatabaseNotFoundException;
 import org.apache.impala.catalog.FeCatalog;
 import org.apache.impala.catalog.FeDataSourceTable;
 import org.apache.impala.catalog.FeDb;
 import org.apache.impala.catalog.FeFsTable;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.FeView;
 import org.apache.impala.catalog.HBaseTable;
 import org.apache.impala.catalog.IncompleteTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.catalog.TableLoadingException;
 import org.apache.impala.catalog.Type;
 import org.apache.impala.common.AnalysisException;
@@ -589,7 +588,7 @@ public class Analyzer {
       if (table instanceof FeView) return new InlineViewRef((FeView) table, tableRef);
       // The table must be a base table.
       Preconditions.checkState(table instanceof FeFsTable ||
-          table instanceof KuduTable ||
+          table instanceof FeKuduTable ||
           table instanceof HBaseTable ||
           table instanceof FeDataSourceTable);
       return new BaseTableRef(tableRef, resolvedPath);

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/CreateTableAsSelectStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/CreateTableAsSelectStmt.java b/fe/src/main/java/org/apache/impala/analysis/CreateTableAsSelectStmt.java
index 76b63c9..33a271b 100644
--- a/fe/src/main/java/org/apache/impala/analysis/CreateTableAsSelectStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/CreateTableAsSelectStmt.java
@@ -25,6 +25,7 @@ import org.apache.impala.authorization.Privilege;
 import org.apache.impala.catalog.Db;
 import org.apache.impala.catalog.FeDb;
 import org.apache.impala.catalog.FeFsTable;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HdfsFileFormat;
 import org.apache.impala.catalog.HdfsTable;
@@ -221,7 +222,7 @@ public class CreateTableAsSelectStmt extends StatementBase {
         tmpTable = HdfsTable.createCtasTarget((Db)db, msTbl);
       }
       Preconditions.checkState(tmpTable != null &&
-          (tmpTable instanceof FeFsTable || tmpTable instanceof KuduTable));
+          (tmpTable instanceof FeFsTable || tmpTable instanceof FeKuduTable));
 
       insertStmt_.setTargetTable(tmpTable);
     } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/InsertStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/InsertStmt.java b/fe/src/main/java/org/apache/impala/analysis/InsertStmt.java
index 32efc2c..72ec828 100644
--- a/fe/src/main/java/org/apache/impala/analysis/InsertStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/InsertStmt.java
@@ -19,18 +19,19 @@ package org.apache.impala.analysis;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
 import org.apache.impala.authorization.Privilege;
 import org.apache.impala.authorization.PrivilegeRequestBuilder;
 import org.apache.impala.catalog.Column;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.FeView;
 import org.apache.impala.catalog.HBaseTable;
 import org.apache.impala.catalog.HdfsTable;
 import org.apache.impala.catalog.KuduColumn;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.catalog.Type;
 import org.apache.impala.catalog.View;
 import org.apache.impala.common.AnalysisException;
@@ -440,7 +441,7 @@ public class InsertStmt extends StatementBase {
 
     // Perform operation-specific analysis.
     if (isUpsert_) {
-      if (!(table_ instanceof KuduTable)) {
+      if (!(table_ instanceof FeKuduTable)) {
         throw new AnalysisException("UPSERT is only supported for Kudu tables");
       }
     } else {
@@ -507,7 +508,7 @@ public class InsertStmt extends StatementBase {
       }
     }
 
-    if (table_ instanceof KuduTable) {
+    if (table_ instanceof FeKuduTable) {
       if (overwrite_) {
         throw new AnalysisException("INSERT OVERWRITE not supported for Kudu tables.");
       }
@@ -536,7 +537,7 @@ public class InsertStmt extends StatementBase {
       // We've already ruled out too many columns in the permutation and partition clauses
       // by checking that there are no duplicates and that every column mentioned actually
       // exists. So all columns aren't mentioned in the query.
-      if (table_ instanceof KuduTable) {
+      if (table_ instanceof FeKuduTable) {
         checkRequiredKuduColumns(mentionedColumnNames);
       } else if (table_ instanceof HBaseTable) {
         checkRequiredHBaseColumns(mentionedColumnNames);
@@ -578,8 +579,8 @@ public class InsertStmt extends StatementBase {
    */
   private void checkRequiredKuduColumns(Set<String> mentionedColumnNames)
       throws AnalysisException {
-    Preconditions.checkState(table_ instanceof KuduTable);
-    List<String> keyColumns = ((KuduTable) table_).getPrimaryKeyColumnNames();
+    Preconditions.checkState(table_ instanceof FeKuduTable);
+    List<String> keyColumns = ((FeKuduTable) table_).getPrimaryKeyColumnNames();
     List<String> missingKeyColumnNames = Lists.newArrayList();
     for (Column column : table_.getColumns()) {
       if (!mentionedColumnNames.contains(column.getName())
@@ -660,10 +661,10 @@ public class InsertStmt extends StatementBase {
     List<String> tmpPartitionKeyNames = new ArrayList<String>();
 
     int numClusteringCols = (tbl instanceof HBaseTable) ? 0 : tbl.getNumClusteringCols();
-    boolean isKuduTable = table_ instanceof KuduTable;
+    boolean isKuduTable = table_ instanceof FeKuduTable;
     Set<String> kuduPartitionColumnNames = null;
     if (isKuduTable) {
-      kuduPartitionColumnNames = ((KuduTable) table_).getPartitionColumnNames();
+      kuduPartitionColumnNames = getKuduPartitionColumnNames((FeKuduTable) table_);
     }
 
     // Check dynamic partition columns for type compatibility.
@@ -759,14 +760,14 @@ public class InsertStmt extends StatementBase {
       }
       // Store exprs for Kudu key columns.
       if (matchFound && isKuduTable) {
-        KuduTable kuduTable = (KuduTable) table_;
-        if (kuduTable.isPrimaryKeyColumn(tblColumn.getName())) {
+        FeKuduTable kuduTable = (FeKuduTable) table_;
+        if (kuduTable.getPrimaryKeyColumnNames().contains(tblColumn.getName())) {
           primaryKeyExprs_.add(Iterables.getLast(resultExprs_));
         }
       }
     }
 
-    if (table_ instanceof KuduTable) {
+    if (table_ instanceof FeKuduTable) {
       Preconditions.checkState(!primaryKeyExprs_.isEmpty());
     }
 
@@ -783,6 +784,14 @@ public class InsertStmt extends StatementBase {
     }
   }
 
+  private static Set<String> getKuduPartitionColumnNames(FeKuduTable table) {
+    Set<String> ret = new HashSet<String>();
+    for (KuduPartitionParam partitionParam : table.getPartitionBy()) {
+      ret.addAll(partitionParam.getColumnNames());
+    }
+    return ret;
+  }
+
   /**
    * Analyzes the 'sort.columns' table property if it is set, and populates
    * sortColumns_ and sortExprs_. If there are errors during the analysis, this will throw

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/KuduPartitionExpr.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/KuduPartitionExpr.java b/fe/src/main/java/org/apache/impala/analysis/KuduPartitionExpr.java
index 08c53fd..e888726 100644
--- a/fe/src/main/java/org/apache/impala/analysis/KuduPartitionExpr.java
+++ b/fe/src/main/java/org/apache/impala/analysis/KuduPartitionExpr.java
@@ -18,9 +18,8 @@
 package org.apache.impala.analysis;
 
 import java.util.List;
-import java.util.Set;
 
-import org.apache.impala.catalog.KuduTable;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.Type;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.thrift.TExprNode;
@@ -30,8 +29,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
 
 /**
  * Internal expr that calls into the Kudu client to determine the partition index for
@@ -43,12 +40,12 @@ public class KuduPartitionExpr extends Expr {
 
   // The table to use the partitioning scheme from.
   private final int targetTableId_;
-  private final KuduTable targetTable_;
+  private final FeKuduTable targetTable_;
   // Maps from this Epxrs children to column positions in the table, i.e. children_[i]
   // produces the value for column partitionColPos_[i].
   private List<Integer> partitionColPos_;
 
-  public KuduPartitionExpr(int targetTableId, KuduTable targetTable,
+  public KuduPartitionExpr(int targetTableId, FeKuduTable targetTable,
       List<Expr> partitionKeyExprs, List<Integer> partitionKeyIdxs) {
     Preconditions.checkState(partitionKeyExprs.size() == partitionKeyIdxs.size());
     targetTableId_ = targetTableId;

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/ModifyStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/ModifyStmt.java b/fe/src/main/java/org/apache/impala/analysis/ModifyStmt.java
index 29266f6..9aa0964 100644
--- a/fe/src/main/java/org/apache/impala/analysis/ModifyStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/ModifyStmt.java
@@ -26,8 +26,8 @@ import java.util.List;
 
 import org.apache.impala.authorization.Privilege;
 import org.apache.impala.catalog.Column;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.catalog.Type;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.common.Pair;
@@ -79,7 +79,7 @@ public abstract class ModifyStmt extends StatementBase {
 
   // Target Kudu table. Since currently only Kudu tables are supported, we use a
   // concrete table class. Result of analysis.
-  protected KuduTable table_;
+  protected FeKuduTable table_;
 
   // END: Members that need to be reset()
   /////////////////////////////////////////
@@ -153,12 +153,12 @@ public abstract class ModifyStmt extends StatementBase {
     Preconditions.checkNotNull(targetTableRef_);
     FeTable dstTbl = targetTableRef_.getTable();
     // Only Kudu tables can be updated
-    if (!(dstTbl instanceof KuduTable)) {
+    if (!(dstTbl instanceof FeKuduTable)) {
       throw new AnalysisException(
           format("Impala does not support modifying a non-Kudu table: %s",
               dstTbl.getFullName()));
     }
-    table_ = (KuduTable) dstTbl;
+    table_ = (FeKuduTable) dstTbl;
 
     // Make sure that the user is allowed to modify the target table. Use ALL because no
     // UPDATE / DELETE privilege exists yet (IMPALA-3840).
@@ -231,7 +231,7 @@ public abstract class ModifyStmt extends StatementBase {
     HashSet<SlotId> keySlots = Sets.newHashSet();
 
     // Mapping from column name to index
-    ArrayList<Column> cols = table_.getColumnsInHiveOrder();
+    List<Column> cols = table_.getColumnsInHiveOrder();
     HashMap<String, Integer> colIndexMap = Maps.newHashMap();
     for (int i = 0; i < cols.size(); i++) {
       colIndexMap.put(cols.get(i).getName(), i);

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/ShowStatsStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/ShowStatsStmt.java b/fe/src/main/java/org/apache/impala/analysis/ShowStatsStmt.java
index 5a7b3bc..04d8703 100644
--- a/fe/src/main/java/org/apache/impala/analysis/ShowStatsStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/ShowStatsStmt.java
@@ -21,9 +21,9 @@ import java.util.List;
 
 import org.apache.impala.authorization.Privilege;
 import org.apache.impala.catalog.FeFsTable;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.FeView;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.AnalysisException;
 import org.apache.impala.thrift.TShowStatsOp;
 import org.apache.impala.thrift.TShowStatsParams;
@@ -87,10 +87,10 @@ public class ShowStatsStmt extends StatementBase {
         throw new AnalysisException(getSqlPrefix() + " must target a Kudu table: " +
             table_.getFullName());
       }
-    } else if (table_ instanceof KuduTable) {
-      KuduTable kuduTable = (KuduTable) table_;
+    } else if (table_ instanceof FeKuduTable) {
+      FeKuduTable kuduTable = (FeKuduTable) table_;
       if (op_ == TShowStatsOp.RANGE_PARTITIONS &&
-          kuduTable.getRangePartitioningColNames().isEmpty()) {
+          FeKuduTable.Utils.getRangePartitioningColNames(kuduTable).isEmpty()) {
         throw new AnalysisException(getSqlPrefix() + " requested but table does not " +
             "have range partitions: " + table_.getFullName());
       }

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java b/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java
index cdd67ce..a669caf 100644
--- a/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java
+++ b/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java
@@ -41,6 +41,7 @@ import org.apache.hadoop.hive.metastore.TableType;
 import org.apache.hadoop.hive.ql.parse.HiveLexer;
 import org.apache.impala.catalog.CatalogException;
 import org.apache.impala.catalog.Column;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.FeView;
 import org.apache.impala.catalog.Function;
@@ -256,8 +257,8 @@ public class ToSqlUtils {
     String storageHandlerClassName = table.getStorageHandlerClassName();
     List<String> primaryKeySql = Lists.newArrayList();
     String kuduPartitionByParams = null;
-    if (table instanceof KuduTable) {
-      KuduTable kuduTable = (KuduTable) table;
+    if (table instanceof FeKuduTable) {
+      FeKuduTable kuduTable = (FeKuduTable) table;
       // Kudu tables don't use LOCATION syntax
       location = null;
       format = HdfsFileFormat.KUDU;

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/analysis/TupleDescriptor.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/TupleDescriptor.java b/fe/src/main/java/org/apache/impala/analysis/TupleDescriptor.java
index f103d8f..22693ad 100644
--- a/fe/src/main/java/org/apache/impala/analysis/TupleDescriptor.java
+++ b/fe/src/main/java/org/apache/impala/analysis/TupleDescriptor.java
@@ -26,9 +26,9 @@ import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.impala.catalog.ColumnStats;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HdfsTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.catalog.StructType;
 import org.apache.impala.thrift.TTupleDescriptor;
 
@@ -323,7 +323,7 @@ public class TupleDescriptor {
    * Returns true if this tuple has at least one materialized nullable Kudu scan slot.
    */
   private boolean hasNullableKuduScanSlots() {
-    if (!(getTable() instanceof KuduTable)) return false;
+    if (!(getTable() instanceof FeKuduTable)) return false;
     for (SlotDescriptor d: slots_) {
       if (d.isMaterialized() && d.getIsNullable()) return true;
     }

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/catalog/FeKuduTable.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/catalog/FeKuduTable.java b/fe/src/main/java/org/apache/impala/catalog/FeKuduTable.java
new file mode 100644
index 0000000..dc5f45d
--- /dev/null
+++ b/fe/src/main/java/org/apache/impala/catalog/FeKuduTable.java
@@ -0,0 +1,221 @@
+// 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.impala.catalog;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.xml.bind.DatatypeConverter;
+
+import org.apache.impala.analysis.KuduPartitionParam;
+import org.apache.impala.common.ImpalaRuntimeException;
+import org.apache.impala.service.BackendConfig;
+import org.apache.impala.thrift.TColumn;
+import org.apache.impala.thrift.TResultSet;
+import org.apache.impala.thrift.TResultSetMetadata;
+import org.apache.impala.util.KuduUtil;
+import org.apache.impala.util.TResultRowBuilder;
+import org.apache.kudu.ColumnSchema;
+import org.apache.kudu.Schema;
+import org.apache.kudu.client.KuduClient;
+import org.apache.kudu.client.LocatedTablet;
+import org.apache.kudu.client.PartitionSchema;
+import org.apache.kudu.client.PartitionSchema.HashBucketSchema;
+import org.apache.kudu.client.PartitionSchema.RangeSchema;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+
+/**
+ * Frontend interface for interacting with a Kudu-backed table.
+ */
+public interface FeKuduTable extends FeTable {
+  /**
+   * Return the comma-separated list of masters for the Kudu cluster
+   * backing this table.
+   */
+  String getKuduMasterHosts();
+
+  /**
+   * Return the name of the Kudu table backing this table.
+   */
+  String getKuduTableName();
+
+  /**
+   * Return the names of the columns that make up the primary key
+   * of this table.
+   */
+  List<String> getPrimaryKeyColumnNames();
+
+  /**
+   * Return the Kudu partitioning clause information.
+   */
+  List<KuduPartitionParam> getPartitionBy();
+
+  /**
+   * Utility functions for acting on FeKuduTable.
+   *
+   * When we fully move to Java 8, these can become default methods of the
+   * interface.
+   */
+  public static abstract class Utils {
+    /**
+     * Returns the range-based partitioning of the given table if it exists,
+     * null otherwise.
+     */
+    private static KuduPartitionParam getRangePartitioning(FeKuduTable table) {
+      for (KuduPartitionParam partitionParam: table.getPartitionBy()) {
+        if (partitionParam.getType() == KuduPartitionParam.Type.RANGE) {
+          return partitionParam;
+        }
+      }
+      return null;
+    }
+
+    /**
+     * Returns the column names of the table's range-based partitioning or an empty
+     * list if the table doesn't have a range-based partitioning.
+     */
+    public static List<String> getRangePartitioningColNames(FeKuduTable table) {
+      KuduPartitionParam rangePartitioning = getRangePartitioning(table);
+      if (rangePartitioning == null) return Collections.<String>emptyList();
+      return rangePartitioning.getColumnNames();
+    }
+
+    public static List<KuduPartitionParam> loadPartitionByParams(
+        org.apache.kudu.client.KuduTable kuduTable) {
+      List<KuduPartitionParam> ret = Lists.newArrayList();
+
+      Preconditions.checkNotNull(kuduTable);
+      Schema tableSchema = kuduTable.getSchema();
+      PartitionSchema partitionSchema = kuduTable.getPartitionSchema();
+      for (HashBucketSchema hashBucketSchema: partitionSchema.getHashBucketSchemas()) {
+        List<String> columnNames = Lists.newArrayList();
+        for (int colId: hashBucketSchema.getColumnIds()) {
+          columnNames.add(getColumnNameById(tableSchema, colId));
+        }
+        ret.add(KuduPartitionParam.createHashParam(columnNames,
+            hashBucketSchema.getNumBuckets()));
+      }
+      RangeSchema rangeSchema = partitionSchema.getRangeSchema();
+      List<Integer> columnIds = rangeSchema.getColumns();
+      if (columnIds.isEmpty()) return ret;
+      List<String> columnNames = Lists.newArrayList();
+      for (int colId: columnIds) columnNames.add(getColumnNameById(tableSchema, colId));
+      // We don't populate the split values because Kudu's API doesn't currently support
+      // retrieving the split values for range partitions.
+      // TODO: File a Kudu JIRA.
+      ret.add(KuduPartitionParam.createRangeParam(columnNames, null));
+
+      return ret;
+    }
+
+    public static TResultSet getTableStats(FeKuduTable table)
+        throws ImpalaRuntimeException {
+      TResultSet result = new TResultSet();
+      TResultSetMetadata resultSchema = new TResultSetMetadata();
+      result.setSchema(resultSchema);
+
+      resultSchema.addToColumns(new TColumn("# Rows", Type.INT.toThrift()));
+      resultSchema.addToColumns(new TColumn("Start Key", Type.STRING.toThrift()));
+      resultSchema.addToColumns(new TColumn("Stop Key", Type.STRING.toThrift()));
+      resultSchema.addToColumns(new TColumn("Leader Replica", Type.STRING.toThrift()));
+      resultSchema.addToColumns(new TColumn("# Replicas", Type.INT.toThrift()));
+
+      KuduClient client = KuduUtil.getKuduClient(table.getKuduMasterHosts());
+      try {
+        org.apache.kudu.client.KuduTable kuduTable = client.openTable(
+            table.getKuduTableName());
+        List<LocatedTablet> tablets =
+            kuduTable.getTabletsLocations(BackendConfig.INSTANCE.getKuduClientTimeoutMs());
+        if (tablets.isEmpty()) {
+          TResultRowBuilder builder = new TResultRowBuilder();
+          result.addToRows(
+              builder.add("-1").add("N/A").add("N/A").add("N/A").add("-1").get());
+          return result;
+        }
+        for (LocatedTablet tab: tablets) {
+          TResultRowBuilder builder = new TResultRowBuilder();
+          builder.add("-1");   // The Kudu client API doesn't expose tablet row counts.
+          builder.add(DatatypeConverter.printHexBinary(
+              tab.getPartition().getPartitionKeyStart()));
+          builder.add(DatatypeConverter.printHexBinary(
+              tab.getPartition().getPartitionKeyEnd()));
+          LocatedTablet.Replica leader = tab.getLeaderReplica();
+          if (leader == null) {
+            // Leader might be null, if it is not yet available (e.g. during
+            // leader election in Kudu)
+            builder.add("Leader n/a");
+          } else {
+            builder.add(leader.getRpcHost() + ":" + leader.getRpcPort().toString());
+          }
+          builder.add(tab.getReplicas().size());
+          result.addToRows(builder.get());
+        }
+
+      } catch (Exception e) {
+        throw new ImpalaRuntimeException("Error accessing Kudu for table stats.", e);
+      }
+      return result;
+    }
+
+    public static TResultSet getRangePartitions(FeKuduTable table)
+        throws ImpalaRuntimeException {
+      TResultSet result = new TResultSet();
+      TResultSetMetadata resultSchema = new TResultSetMetadata();
+      result.setSchema(resultSchema);
+
+      // Build column header
+      String header = "RANGE (" + Joiner.on(',').join(
+          Utils.getRangePartitioningColNames(table)) + ")";
+      resultSchema.addToColumns(new TColumn(header, Type.STRING.toThrift()));
+      KuduClient client = KuduUtil.getKuduClient(table.getKuduMasterHosts());
+      try {
+        org.apache.kudu.client.KuduTable kuduTable = client.openTable(
+            table.getKuduTableName());
+        // The Kudu table API will return the partitions in sorted order by value.
+        List<String> partitions = kuduTable.getFormattedRangePartitions(
+            BackendConfig.INSTANCE.getKuduClientTimeoutMs());
+        if (partitions.isEmpty()) {
+          TResultRowBuilder builder = new TResultRowBuilder();
+          result.addToRows(builder.add("").get());
+          return result;
+        }
+        for (String partition: partitions) {
+          TResultRowBuilder builder = new TResultRowBuilder();
+          builder.add(partition);
+          result.addToRows(builder.get());
+        }
+      } catch (Exception e) {
+        throw new ImpalaRuntimeException("Error accessing Kudu for table partitions.", e);
+      }
+      return result;
+    }
+
+    /**
+     * Returns the name of a Kudu column with id 'colId'.
+     */
+    private static String getColumnNameById(Schema tableSchema, int colId) {
+      Preconditions.checkNotNull(tableSchema);
+      ColumnSchema col = tableSchema.getColumnByIndex(tableSchema.getColumnIndex(colId));
+      Preconditions.checkNotNull(col);
+      return col.getName();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/catalog/KuduTable.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/catalog/KuduTable.java b/fe/src/main/java/org/apache/impala/catalog/KuduTable.java
index 5d6a10d..e277d3c 100644
--- a/fe/src/main/java/org/apache/impala/catalog/KuduTable.java
+++ b/fe/src/main/java/org/apache/impala/catalog/KuduTable.java
@@ -18,13 +18,9 @@
 package org.apache.impala.catalog;
 
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import javax.xml.bind.DatatypeConverter;
-
 import org.apache.hadoop.hive.common.StatsSetupConst;
 import org.apache.hadoop.hive.metastore.IMetaStoreClient;
 import org.apache.hadoop.hive.metastore.api.FieldSchema;
@@ -32,30 +28,18 @@ import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
 import org.apache.impala.analysis.ColumnDef;
 import org.apache.impala.analysis.KuduPartitionParam;
 import org.apache.impala.common.ImpalaRuntimeException;
-import org.apache.impala.service.BackendConfig;
-import org.apache.impala.service.CatalogOpExecutor;
 import org.apache.impala.thrift.TCatalogObjectType;
-import org.apache.impala.thrift.TColumn;
 import org.apache.impala.thrift.TKuduPartitionByHashParam;
 import org.apache.impala.thrift.TKuduPartitionByRangeParam;
 import org.apache.impala.thrift.TKuduPartitionParam;
 import org.apache.impala.thrift.TKuduTable;
-import org.apache.impala.thrift.TResultSet;
-import org.apache.impala.thrift.TResultSetMetadata;
 import org.apache.impala.thrift.TTable;
 import org.apache.impala.thrift.TTableDescriptor;
 import org.apache.impala.thrift.TTableType;
 import org.apache.impala.util.KuduUtil;
-import org.apache.impala.util.TResultRowBuilder;
 import org.apache.kudu.ColumnSchema;
-import org.apache.kudu.Schema;
 import org.apache.kudu.client.KuduClient;
 import org.apache.kudu.client.KuduException;
-import org.apache.kudu.client.LocatedTablet;
-import org.apache.kudu.client.PartitionSchema;
-import org.apache.kudu.client.PartitionSchema.HashBucketSchema;
-import org.apache.kudu.client.PartitionSchema.RangeSchema;
-import org.apache.log4j.Logger;
 import org.apache.thrift.TException;
 
 import com.codahale.metrics.Timer;
@@ -67,7 +51,7 @@ import com.google.common.collect.Lists;
 /**
  * Representation of a Kudu table in the catalog cache.
  */
-public class KuduTable extends Table {
+public class KuduTable extends Table implements FeKuduTable {
 
   // Alias to the string key that identifies the storage handler for Kudu tables.
   public static final String KEY_STORAGE_HANDLER =
@@ -112,7 +96,7 @@ public class KuduTable extends Table {
 
   // Partitioning schemes of this Kudu table. Both range and hash-based partitioning are
   // supported.
-  private final List<KuduPartitionParam> partitionBy_ = Lists.newArrayList();
+  private List<KuduPartitionParam> partitionBy_;
 
   // Schema of the underlying Kudu table.
   private org.apache.kudu.Schema kuduSchema_;
@@ -140,48 +124,24 @@ public class KuduTable extends Table {
     return KUDU_STORAGE_HANDLER.equals(msTbl.getParameters().get(KEY_STORAGE_HANDLER));
   }
 
+  @Override
   public String getKuduTableName() { return kuduTableName_; }
+  @Override
   public String getKuduMasterHosts() { return kuduMasters_; }
+
   public org.apache.kudu.Schema getKuduSchema() { return kuduSchema_; }
 
+  @Override
   public List<String> getPrimaryKeyColumnNames() {
     return ImmutableList.copyOf(primaryKeyColumnNames_);
   }
 
+  @Override
   public List<KuduPartitionParam> getPartitionBy() {
+    Preconditions.checkState(partitionBy_ != null);
     return ImmutableList.copyOf(partitionBy_);
   }
 
-  public Set<String> getPartitionColumnNames() {
-    Set<String> ret = new HashSet<String>();
-    for (KuduPartitionParam partitionParam : partitionBy_) {
-      ret.addAll(partitionParam.getColumnNames());
-    }
-    return ret;
-  }
-
-  /**
-   * Returns the range-based partitioning of this table if it exists, null otherwise.
-   */
-  private KuduPartitionParam getRangePartitioning() {
-    for (KuduPartitionParam partitionParam: partitionBy_) {
-      if (partitionParam.getType() == KuduPartitionParam.Type.RANGE) {
-        return partitionParam;
-      }
-    }
-    return null;
-  }
-
-  /**
-   * Returns the column names of the table's range-based partitioning or an empty
-   * list if the table doesn't have a range-based partitioning.
-   */
-  public List<String> getRangePartitioningColNames() {
-    KuduPartitionParam rangePartitioning = getRangePartitioning();
-    if (rangePartitioning == null) return Collections.<String>emptyList();
-    return rangePartitioning.getColumnNames();
-  }
-
   /**
    * Load schema and partitioning schemes directly from Kudu.
    */
@@ -203,7 +163,8 @@ public class KuduTable extends Table {
     Preconditions.checkNotNull(kuduTable);
 
     loadSchema(kuduTable);
-    loadPartitionByParams(kuduTable);
+    Preconditions.checkState(!colsByPos_.isEmpty());
+    partitionBy_ = Utils.loadPartitionByParams(kuduTable);
   }
 
   /**
@@ -282,40 +243,6 @@ public class KuduTable extends Table {
     }
   }
 
-  private void loadPartitionByParams(org.apache.kudu.client.KuduTable kuduTable) {
-    Preconditions.checkNotNull(kuduTable);
-    Schema tableSchema = kuduTable.getSchema();
-    PartitionSchema partitionSchema = kuduTable.getPartitionSchema();
-    Preconditions.checkState(!colsByPos_.isEmpty());
-    partitionBy_.clear();
-    for (HashBucketSchema hashBucketSchema: partitionSchema.getHashBucketSchemas()) {
-      List<String> columnNames = Lists.newArrayList();
-      for (int colId: hashBucketSchema.getColumnIds()) {
-        columnNames.add(getColumnNameById(tableSchema, colId));
-      }
-      partitionBy_.add(KuduPartitionParam.createHashParam(columnNames,
-          hashBucketSchema.getNumBuckets()));
-    }
-    RangeSchema rangeSchema = partitionSchema.getRangeSchema();
-    List<Integer> columnIds = rangeSchema.getColumns();
-    if (columnIds.isEmpty()) return;
-    List<String> columnNames = Lists.newArrayList();
-    for (int colId: columnIds) columnNames.add(getColumnNameById(tableSchema, colId));
-    // We don't populate the split values because Kudu's API doesn't currently support
-    // retrieving the split values for range partitions.
-    // TODO: File a Kudu JIRA.
-    partitionBy_.add(KuduPartitionParam.createRangeParam(columnNames, null));
-  }
-
-  /**
-   * Returns the name of a Kudu column with id 'colId'.
-   */
-  private String getColumnNameById(Schema tableSchema, int colId) {
-    Preconditions.checkNotNull(tableSchema);
-    ColumnSchema col = tableSchema.getColumnByIndex(tableSchema.getColumnIndex(colId));
-    Preconditions.checkNotNull(col);
-    return col.getName();
-  }
 
   /**
    * Creates a temporary KuduTable object populated with the specified properties but has
@@ -333,7 +260,7 @@ public class KuduTable extends Table {
     for (ColumnDef pkColDef: primaryKeyColumnDefs) {
       tmpTable.primaryKeyColumnNames_.add(pkColDef.getColName());
     }
-    tmpTable.partitionBy_.addAll(partitionParams);
+    tmpTable.partitionBy_ = ImmutableList.copyOf(partitionParams);
     return tmpTable;
   }
 
@@ -353,23 +280,25 @@ public class KuduTable extends Table {
     kuduMasters_ = Joiner.on(',').join(tkudu.getMaster_addresses());
     primaryKeyColumnNames_.clear();
     primaryKeyColumnNames_.addAll(tkudu.getKey_columns());
-    loadPartitionByParamsFromThrift(tkudu.getPartition_by());
+    partitionBy_ = loadPartitionByParamsFromThrift(tkudu.getPartition_by());
   }
 
-  private void loadPartitionByParamsFromThrift(List<TKuduPartitionParam> params) {
-    partitionBy_.clear();
+  private static List<KuduPartitionParam> loadPartitionByParamsFromThrift(
+      List<TKuduPartitionParam> params) {
+    List<KuduPartitionParam> ret= Lists.newArrayList();
     for (TKuduPartitionParam param: params) {
       if (param.isSetBy_hash_param()) {
         TKuduPartitionByHashParam hashParam = param.getBy_hash_param();
-        partitionBy_.add(KuduPartitionParam.createHashParam(
+        ret.add(KuduPartitionParam.createHashParam(
             hashParam.getColumns(), hashParam.getNum_partitions()));
       } else {
         Preconditions.checkState(param.isSetBy_range_param());
         TKuduPartitionByRangeParam rangeParam = param.getBy_range_param();
-        partitionBy_.add(KuduPartitionParam.createRangeParam(rangeParam.getColumns(),
+        ret.add(KuduPartitionParam.createRangeParam(rangeParam.getColumns(),
             null));
       }
     }
+    return ret;
   }
 
   @Override
@@ -395,85 +324,4 @@ public class KuduTable extends Table {
     }
     return tbl;
   }
-
-  public boolean isPrimaryKeyColumn(String name) {
-    return primaryKeyColumnNames_.contains(name);
-  }
-
-  public TResultSet getTableStats() throws ImpalaRuntimeException {
-    TResultSet result = new TResultSet();
-    TResultSetMetadata resultSchema = new TResultSetMetadata();
-    result.setSchema(resultSchema);
-
-    resultSchema.addToColumns(new TColumn("# Rows", Type.INT.toThrift()));
-    resultSchema.addToColumns(new TColumn("Start Key", Type.STRING.toThrift()));
-    resultSchema.addToColumns(new TColumn("Stop Key", Type.STRING.toThrift()));
-    resultSchema.addToColumns(new TColumn("Leader Replica", Type.STRING.toThrift()));
-    resultSchema.addToColumns(new TColumn("# Replicas", Type.INT.toThrift()));
-
-    KuduClient client = KuduUtil.getKuduClient(getKuduMasterHosts());
-    try {
-      org.apache.kudu.client.KuduTable kuduTable = client.openTable(kuduTableName_);
-      List<LocatedTablet> tablets =
-          kuduTable.getTabletsLocations(BackendConfig.INSTANCE.getKuduClientTimeoutMs());
-      if (tablets.isEmpty()) {
-        TResultRowBuilder builder = new TResultRowBuilder();
-        result.addToRows(
-            builder.add("-1").add("N/A").add("N/A").add("N/A").add("-1").get());
-        return result;
-      }
-      for (LocatedTablet tab: tablets) {
-        TResultRowBuilder builder = new TResultRowBuilder();
-        builder.add("-1");   // The Kudu client API doesn't expose tablet row counts.
-        builder.add(DatatypeConverter.printHexBinary(
-            tab.getPartition().getPartitionKeyStart()));
-        builder.add(DatatypeConverter.printHexBinary(
-            tab.getPartition().getPartitionKeyEnd()));
-        LocatedTablet.Replica leader = tab.getLeaderReplica();
-        if (leader == null) {
-          // Leader might be null, if it is not yet available (e.g. during
-          // leader election in Kudu)
-          builder.add("Leader n/a");
-        } else {
-          builder.add(leader.getRpcHost() + ":" + leader.getRpcPort().toString());
-        }
-        builder.add(tab.getReplicas().size());
-        result.addToRows(builder.get());
-      }
-
-    } catch (Exception e) {
-      throw new ImpalaRuntimeException("Error accessing Kudu for table stats.", e);
-    }
-    return result;
-  }
-
-  public TResultSet getRangePartitions() throws ImpalaRuntimeException {
-    TResultSet result = new TResultSet();
-    TResultSetMetadata resultSchema = new TResultSetMetadata();
-    result.setSchema(resultSchema);
-
-    // Build column header
-    String header = "RANGE (" + Joiner.on(',').join(getRangePartitioningColNames()) + ")";
-    resultSchema.addToColumns(new TColumn(header, Type.STRING.toThrift()));
-    KuduClient client = KuduUtil.getKuduClient(getKuduMasterHosts());
-    try {
-      org.apache.kudu.client.KuduTable kuduTable = client.openTable(kuduTableName_);
-      // The Kudu table API will return the partitions in sorted order by value.
-      List<String> partitions = kuduTable.getFormattedRangePartitions(
-          BackendConfig.INSTANCE.getKuduClientTimeoutMs());
-      if (partitions.isEmpty()) {
-        TResultRowBuilder builder = new TResultRowBuilder();
-        result.addToRows(builder.add("").get());
-        return result;
-      }
-      for (String partition: partitions) {
-        TResultRowBuilder builder = new TResultRowBuilder();
-        builder.add(partition);
-        result.addToRows(builder.get());
-      }
-    } catch (Exception e) {
-      throw new ImpalaRuntimeException("Error accessing Kudu for table partitions.", e);
-    }
-    return result;
-  }
 }

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/catalog/local/LocalCatalog.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/LocalCatalog.java b/fe/src/main/java/org/apache/impala/catalog/local/LocalCatalog.java
index 542ec32..03438c6 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/LocalCatalog.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/LocalCatalog.java
@@ -66,14 +66,15 @@ public class LocalCatalog implements FeCatalog {
   private final MetaProvider metaProvider_;
   private Map<String, FeDb> dbs_ = Maps.newHashMap();
   private String nullPartitionKeyValue_;
+  private final String defaultKuduMasterHosts_;
 
-  public static FeCatalog create(String defaultKuduMasterHosts) {
-    // TODO(todd): store the kudu master hosts
-    return new LocalCatalog(new DirectMetaProvider());
+  public static LocalCatalog create(String defaultKuduMasterHosts) {
+    return new LocalCatalog(new DirectMetaProvider(), defaultKuduMasterHosts);
   }
 
-  public LocalCatalog(MetaProvider metaProvider) {
+  private LocalCatalog(MetaProvider metaProvider, String defaultKuduMasterHosts) {
     metaProvider_ = Preconditions.checkNotNull(metaProvider);
+    defaultKuduMasterHosts_ = defaultKuduMasterHosts;
   }
 
   @Override
@@ -198,7 +199,7 @@ public class LocalCatalog implements FeCatalog {
 
   @Override
   public String getDefaultKuduMasterHosts() {
-    throw new UnsupportedOperationException("TODO");
+    return defaultKuduMasterHosts_;
   }
 
   public String getNullPartitionKeyValue() {

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/catalog/local/LocalFsTable.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/LocalFsTable.java b/fe/src/main/java/org/apache/impala/catalog/local/LocalFsTable.java
index b652e0d..5a5f3bd 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/LocalFsTable.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/LocalFsTable.java
@@ -27,6 +27,8 @@ import java.util.Set;
 import java.util.TreeMap;
 
 import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.serde.serdeConstants;
 import org.apache.impala.analysis.LiteralExpr;
 import org.apache.impala.analysis.NullLiteral;
 import org.apache.impala.catalog.CatalogException;
@@ -79,14 +81,26 @@ public class LocalFsTable extends LocalTable implements FeFsTable {
    */
   private ArrayList<HashSet<Long>> nullPartitionIds_;
 
+
+  /**
+   * The value that will be stored in a partition name to indicate NULL.
+   */
+  private final String nullColumnValue_;
+
   /**
    * Map assigning integer indexes for the hosts containing blocks for this table.
    * This is updated as a side effect of LocalFsPartition.loadFileDescriptors().
    */
   private final ListMap<TNetworkAddress> hostIndex_ = new ListMap<>();
 
-  public LocalFsTable(LocalDb db, String tblName, SchemaInfo schemaInfo) {
-    super(db, tblName, schemaInfo);
+  public LocalFsTable(LocalDb db, Table msTbl) {
+    super(db, msTbl);
+
+    // set NULL indicator string from table properties
+    String tableNullFormat =
+        msTbl.getParameters().get(serdeConstants.SERIALIZATION_NULL_FORMAT);
+    nullColumnValue_ = tableNullFormat != null ? tableNullFormat :
+        FeFsTable.DEFAULT_NULL_COLUMN_VALUE;
   }
 
   @Override
@@ -188,7 +202,7 @@ public class LocalFsTable extends LocalTable implements FeFsTable {
 
     // TODO(todd): implement avro schema support
     THdfsTable hdfsTable = new THdfsTable(getHdfsBaseDir(), getColumnNames(),
-        getNullPartitionKeyValue(), schemaInfo_.getNullColumnValue(), idToPartition,
+        getNullPartitionKeyValue(), nullColumnValue_, idToPartition,
         tPrototypePartition);
 
     TTableDescriptor tableDesc = new TTableDescriptor(tableId, TTableType.HDFS_TABLE,

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/catalog/local/LocalKuduTable.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/LocalKuduTable.java b/fe/src/main/java/org/apache/impala/catalog/local/LocalKuduTable.java
new file mode 100644
index 0000000..e12e3ac
--- /dev/null
+++ b/fe/src/main/java/org/apache/impala/catalog/local/LocalKuduTable.java
@@ -0,0 +1,202 @@
+// 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.impala.catalog.local;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.concurrent.Immutable;
+
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.impala.analysis.KuduPartitionParam;
+import org.apache.impala.catalog.Column;
+import org.apache.impala.catalog.FeCatalogUtils;
+import org.apache.impala.catalog.FeKuduTable;
+import org.apache.impala.catalog.KuduColumn;
+import org.apache.impala.catalog.KuduTable;
+import org.apache.impala.common.ImpalaRuntimeException;
+import org.apache.impala.thrift.TKuduTable;
+import org.apache.impala.thrift.TTableDescriptor;
+import org.apache.impala.thrift.TTableType;
+import org.apache.impala.util.KuduUtil;
+import org.apache.kudu.ColumnSchema;
+import org.apache.kudu.Schema;
+import org.apache.kudu.client.KuduClient;
+import org.apache.kudu.client.KuduException;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
+public class LocalKuduTable extends LocalTable implements FeKuduTable {
+  private final TableParams tableParams_;
+  private final List<KuduPartitionParam> partitionBy_;
+  private final org.apache.kudu.client.KuduTable kuduTable_;
+  private final ImmutableList<String> primaryKeyColumnNames_;
+
+  /**
+   * Create a new instance based on the table metadata 'msTable' stored
+   * in the metastore.
+   */
+  static LocalTable loadFromKudu(LocalDb db, Table msTable) {
+    Preconditions.checkNotNull(db);
+    Preconditions.checkNotNull(msTable);
+    String fullTableName = msTable.getDbName() + "." + msTable.getTableName();
+
+    TableParams params = new TableParams(msTable);
+    org.apache.kudu.client.KuduTable kuduTable = params.openTable();
+    List<Column> cols = new ArrayList<>();
+    List<FieldSchema> fieldSchemas = new ArrayList<>();
+    convertColsFromKudu(kuduTable.getSchema(), cols, fieldSchemas);
+
+    // TODO(todd): update the schema in HMS if it doesn't match? This will
+    // no longer be necessary after the Kudu-HMS integration is complete, so
+    // maybe not worth implementing here for the LocalCatalog implementation.
+
+    // Use the schema derived from Kudu, rather than the one stored in the HMS.
+    msTable.getSd().setCols(fieldSchemas);
+
+    ColumnMap cmap = new ColumnMap(cols, /*numClusteringCols=*/0, fullTableName);
+    return new LocalKuduTable(db, msTable, cmap, kuduTable);
+  }
+
+  private static void convertColsFromKudu(Schema schema, List<Column> cols,
+      List<FieldSchema> fieldSchemas) {
+    Preconditions.checkArgument(cols.isEmpty());;
+    Preconditions.checkArgument(fieldSchemas.isEmpty());;
+
+    int pos = 0;
+    for (ColumnSchema colSchema: schema.getColumns()) {
+      KuduColumn kuduCol;
+      try {
+        kuduCol = KuduColumn.fromColumnSchema(colSchema, pos++);
+      } catch (ImpalaRuntimeException e) {
+        throw new LocalCatalogException(e);
+      }
+      Preconditions.checkNotNull(kuduCol);
+      // Add the HMS column
+      fieldSchemas.add(new FieldSchema(kuduCol.getName(),
+          kuduCol.getType().toSql().toLowerCase(), /*comment=*/null));
+      cols.add(kuduCol);
+    }
+  }
+
+  private LocalKuduTable(LocalDb db, Table msTable, ColumnMap cmap,
+      org.apache.kudu.client.KuduTable kuduTable) {
+    super(db, msTable, cmap);
+    tableParams_ = new TableParams(msTable);
+    kuduTable_ = kuduTable;
+    partitionBy_ = ImmutableList.copyOf(Utils.loadPartitionByParams(
+        kuduTable));
+
+    ImmutableList.Builder<String> b = ImmutableList.builder();
+    for (ColumnSchema c: kuduTable_.getSchema().getPrimaryKeyColumns()) {
+      b.add(c.getName().toLowerCase());
+    }
+    primaryKeyColumnNames_ = b.build();
+  }
+
+  @Override
+  public String getKuduMasterHosts() {
+    return tableParams_.masters_;
+  }
+
+
+  @Override
+  public String getKuduTableName() {
+    return tableParams_.kuduTableName_;
+  }
+
+  @Override
+  public List<String> getPrimaryKeyColumnNames() {
+    return primaryKeyColumnNames_;
+  }
+
+  @Override
+  public List<KuduPartitionParam> getPartitionBy() {
+    return partitionBy_;
+  }
+
+  @Override
+  public TTableDescriptor toThriftDescriptor(int tableId,
+      Set<Long> referencedPartitions) {
+    // TODO(todd): the old implementation passes kuduTableName_ instead of name below.
+    TTableDescriptor desc = new TTableDescriptor(tableId, TTableType.KUDU_TABLE,
+        FeCatalogUtils.getTColumnDescriptors(this),
+        getNumClusteringCols(),
+        name_, db_.getName());
+    TKuduTable tbl = new TKuduTable();
+    tbl.setKey_columns(Preconditions.checkNotNull(primaryKeyColumnNames_));
+    tbl.setMaster_addresses(tableParams_.getMastersAsList());
+    tbl.setTable_name(tableParams_.kuduTableName_);
+    Preconditions.checkNotNull(partitionBy_);
+    // IMPALA-5154: partitionBy_ may be empty if Kudu table created outside Impala,
+    // partition_by must be explicitly created because the field is required.
+    tbl.partition_by = Lists.newArrayList();
+    for (KuduPartitionParam partitionParam: partitionBy_) {
+      tbl.addToPartition_by(partitionParam.toThrift());
+    }
+    desc.setKuduTable(tbl);
+    return desc;
+  }
+
+  /**
+   * Parsed parameters from the HMS indicating the cluster and table name for
+   * a Kudu table.
+   */
+  @Immutable
+  private static class TableParams {
+    private final String kuduTableName_;
+    private final String masters_;
+
+    TableParams(Table msTable) {
+      String fullTableName = msTable.getDbName() + "." + msTable.getTableName();
+      Map<String, String> params = msTable.getParameters();
+      kuduTableName_ = params.get(KuduTable.KEY_TABLE_NAME);
+      if (kuduTableName_ == null) {
+        throw new LocalCatalogException("No " + KuduTable.KEY_TABLE_NAME +
+            " property found for table " + fullTableName);
+      }
+      masters_ = params.get(KuduTable.KEY_MASTER_HOSTS);
+      if (masters_ == null) {
+        throw new LocalCatalogException("No " + KuduTable.KEY_MASTER_HOSTS +
+            " property found for table " + fullTableName);
+      }
+    }
+
+    public List<String> getMastersAsList() {
+      return Lists.newArrayList(masters_.split(","));
+    }
+
+    public org.apache.kudu.client.KuduTable openTable() {
+      KuduClient kuduClient = KuduUtil.getKuduClient(masters_);
+      org.apache.kudu.client.KuduTable kuduTable;
+      try {
+        kuduTable = kuduClient.openTable(kuduTableName_);
+      } catch (KuduException e) {
+        throw new LocalCatalogException(
+            String.format("Error opening Kudu table '%s', Kudu error: %s",
+                kuduTableName_, e.getMessage()));
+      }
+      return kuduTable;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/catalog/local/LocalTable.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/LocalTable.java b/fe/src/main/java/org/apache/impala/catalog/local/LocalTable.java
index d128ca2..57da5f2 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/LocalTable.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/LocalTable.java
@@ -20,19 +20,15 @@ package org.apache.impala.catalog.local;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.annotation.concurrent.Immutable;
-
 import org.apache.hadoop.hive.metastore.TableType;
 import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
 import org.apache.hadoop.hive.metastore.api.Table;
-import org.apache.hadoop.hive.serde.serdeConstants;
 import org.apache.impala.analysis.TableName;
 import org.apache.impala.catalog.ArrayType;
 import org.apache.impala.catalog.Column;
 import org.apache.impala.catalog.DataSourceTable;
 import org.apache.impala.catalog.FeCatalogUtils;
 import org.apache.impala.catalog.FeDb;
-import org.apache.impala.catalog.FeFsTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HBaseTable;
 import org.apache.impala.catalog.HdfsFileFormat;
@@ -63,25 +59,30 @@ abstract class LocalTable implements FeTable {
   protected final LocalDb db_;
   /** The lower-case name of the table. */
   protected final String name_;
-  protected final SchemaInfo schemaInfo_;
+
+  private final ColumnMap cols_;
+
+  protected final Table msTable_;
+
+  private final TTableStats tableStats_;
 
   public static LocalTable load(LocalDb db, String tblName) {
     // In order to know which kind of table subclass to instantiate, we need
     // to eagerly grab and parse the top-level Table object from the HMS.
-    SchemaInfo schemaInfo = SchemaInfo.load(db, tblName);
     LocalTable t = null;
-    Table msTbl = schemaInfo.msTable_;
+    Table msTbl = loadMsTable(db, tblName);
     if (TableType.valueOf(msTbl.getTableType()) == TableType.VIRTUAL_VIEW) {
-      t = new LocalView(db, tblName, schemaInfo);
+      t = new LocalView(db, msTbl);
     } else if (HBaseTable.isHBaseTable(msTbl)) {
       // TODO(todd) support HBase table
     } else if (KuduTable.isKuduTable(msTbl)) {
       // TODO(todd) support kudu table
+      t = LocalKuduTable.loadFromKudu(db, msTbl);
     } else if (DataSourceTable.isDataSourceTable(msTbl)) {
       // TODO(todd) support datasource table
     } else if (HdfsFileFormat.isHdfsInputFormatClass(
-        schemaInfo.msTable_.getSd().getInputFormat())) {
-      t = new LocalFsTable(db, tblName, schemaInfo);
+        msTbl.getSd().getInputFormat())) {
+      t = new LocalFsTable(db, msTbl);
     }
 
     if (t == null) {
@@ -96,11 +97,38 @@ abstract class LocalTable implements FeTable {
     t.loadColumnStats();
     return t;
   }
-  public LocalTable(LocalDb db, String tblName, SchemaInfo schemaInfo) {
-    this.db_ = Preconditions.checkNotNull(db);
-    this.name_ = Preconditions.checkNotNull(tblName);
-    this.schemaInfo_ = Preconditions.checkNotNull(schemaInfo);
+
+
+  /**
+   * Load the Table instance from the metastore.
+   */
+  private static Table loadMsTable(LocalDb db, String tblName) {
     Preconditions.checkArgument(tblName.toLowerCase().equals(tblName));
+
+    try {
+      return db.getCatalog().getMetaProvider().loadTable(db.getName(), tblName);
+    } catch (TException e) {
+      throw new LocalCatalogException(String.format(
+          "Could not load table %s.%s from metastore",
+          db.getName(), tblName), e);
+    }
+  }
+
+  public LocalTable(LocalDb db, Table msTbl, ColumnMap cols) {
+    this.db_ = Preconditions.checkNotNull(db);
+    this.name_ = msTbl.getTableName();
+    this.cols_ = cols;
+
+    this.msTable_ = msTbl;
+
+    tableStats_ = new TTableStats(
+        FeCatalogUtils.getRowCount(msTable_.getParameters()));
+    tableStats_.setTotal_file_bytes(
+        FeCatalogUtils.getTotalSize(msTable_.getParameters()));
+  }
+
+  public LocalTable(LocalDb db, Table msTbl) {
+    this(db, msTbl, ColumnMap.fromMsTable(msTbl));
   }
 
   @Override
@@ -110,7 +138,7 @@ abstract class LocalTable implements FeTable {
 
   @Override
   public Table getMetaStoreTable() {
-    return schemaInfo_.msTable_;
+    return msTable_;
   }
 
   @Override
@@ -142,7 +170,7 @@ abstract class LocalTable implements FeTable {
   @Override
   public ArrayList<Column> getColumns() {
     // TODO(todd) why does this return ArrayList instead of List?
-    return new ArrayList<>(schemaInfo_.colsByPos_);
+    return new ArrayList<>(cols_.colsByPos_);
   }
 
   @Override
@@ -154,40 +182,37 @@ abstract class LocalTable implements FeTable {
 
   @Override
   public List<String> getColumnNames() {
-    return Column.toColumnNames(schemaInfo_.colsByPos_);
+    return cols_.getColumnNames();
   }
 
   @Override
   public List<Column> getClusteringColumns() {
-    return ImmutableList.copyOf(
-        schemaInfo_.colsByPos_.subList(0, schemaInfo_.numClusteringCols_));
+    return cols_.getClusteringColumns();
   }
 
   @Override
   public List<Column> getNonClusteringColumns() {
-    return ImmutableList.copyOf(schemaInfo_.colsByPos_.subList(
-        schemaInfo_.numClusteringCols_,
-        schemaInfo_.colsByPos_.size()));
+    return cols_.getNonClusteringColumns();
   }
 
   @Override
   public int getNumClusteringCols() {
-    return schemaInfo_.numClusteringCols_;
+    return cols_.getNumClusteringCols();
   }
 
   @Override
   public boolean isClusteringColumn(Column c) {
-    return schemaInfo_.isClusteringColumn(c);
+    return cols_.isClusteringColumn(c);
   }
 
   @Override
   public Column getColumn(String name) {
-    return schemaInfo_.colsByName_.get(name.toLowerCase());
+    return cols_.getByName(name);
   }
 
   @Override
   public ArrayType getType() {
-    return schemaInfo_.type_;
+    return cols_.getType();
   }
 
   @Override
@@ -197,12 +222,12 @@ abstract class LocalTable implements FeTable {
 
   @Override
   public long getNumRows() {
-    return schemaInfo_.tableStats_.num_rows;
+    return tableStats_.num_rows;
   }
 
   @Override
   public TTableStats getTTableStats() {
-    return schemaInfo_.tableStats_;
+    return tableStats_;
   }
 
   protected void loadColumnStats() {
@@ -215,75 +240,75 @@ abstract class LocalTable implements FeTable {
     }
   }
 
-  /**
-   * The table schema, loaded from the HMS Table object. This is common
-   * to all Table implementations and includes the column definitions and
-   * table-level stats.
-   *
-   * TODO(todd): some of this code is lifted from 'Table' and, with some
-   * effort, could be refactored to avoid duplication.
-   */
-  @Immutable
-  protected static class SchemaInfo {
-    private final Table msTable_;
-
+  protected static class ColumnMap {
     private final ArrayType type_;
     private final ImmutableList<Column> colsByPos_;
     private final ImmutableMap<String, Column> colsByName_;
 
     private final int numClusteringCols_;
-    private final String nullColumnValue_;
 
-    private final TTableStats tableStats_;
+    public static ColumnMap fromMsTable(Table msTbl) {
+      final String fullName = msTbl.getDbName() + "." + msTbl.getTableName();
+
+      // The number of clustering columns is the number of partition keys.
+      int numClusteringCols = msTbl.getPartitionKeys().size();
+      // Add all columns to the table. Ordering is important: partition columns first,
+      // then all other columns.
+      List<Column> cols;
+      try {
+        cols = FeCatalogUtils.fieldSchemasToColumns(
+            Iterables.concat(msTbl.getPartitionKeys(),
+                             msTbl.getSd().getCols()),
+            msTbl.getTableName());
+        return new ColumnMap(cols, numClusteringCols, fullName);
+      } catch (TableLoadingException e) {
+        throw new LocalCatalogException(e);
+      }
+    }
+
+    public ColumnMap(List<Column> cols, int numClusteringCols,
+        String fullTableName) {
+      this.colsByPos_ = ImmutableList.copyOf(cols);
+      this.numClusteringCols_ = numClusteringCols;
+      colsByName_ = indexColumnNames(colsByPos_);
+      type_ = new ArrayType(columnsToStructType(colsByPos_));
 
-    /**
-     * Load the schema info from the metastore.
-     */
-    static SchemaInfo load(LocalDb db, String tblName) {
       try {
-        Table msTbl = db.getCatalog().getMetaProvider().loadTable(
-            db.getName(), tblName);
-        return new SchemaInfo(msTbl);
-      } catch (TException e) {
-        throw new LocalCatalogException(String.format(
-            "Could not load table %s.%s from metastore",
-            db.getName(), tblName), e);
+        FeCatalogUtils.validateClusteringColumns(
+            colsByPos_.subList(0, numClusteringCols_),
+            fullTableName);
       } catch (TableLoadingException e) {
-        // In this case, the exception message already has the table name
-        // in the exception message.
         throw new LocalCatalogException(e);
       }
     }
 
-    SchemaInfo(Table msTbl) throws TableLoadingException {
-      msTable_ = msTbl;
-      // set NULL indicator string from table properties
-      String tableNullFormat =
-          msTbl.getParameters().get(serdeConstants.SERIALIZATION_NULL_FORMAT);
-      nullColumnValue_ = tableNullFormat != null ? tableNullFormat :
-          FeFsTable.DEFAULT_NULL_COLUMN_VALUE;
+    public ArrayType getType() {
+      return type_;
+    }
 
-      final String fullName = msTbl.getDbName() + "." + msTbl.getTableName();
 
-      // The number of clustering columns is the number of partition keys.
-      numClusteringCols_ = msTbl.getPartitionKeys().size();
-      // Add all columns to the table. Ordering is important: partition columns first,
-      // then all other columns.
-      colsByPos_ = FeCatalogUtils.fieldSchemasToColumns(
-          Iterables.concat(msTbl.getPartitionKeys(),
-                           msTbl.getSd().getCols()),
-          fullName);
-      FeCatalogUtils.validateClusteringColumns(
-          colsByPos_.subList(0, numClusteringCols_), fullName);
-      colsByName_ = indexColumnNames(colsByPos_);
-      type_ = new ArrayType(columnsToStructType(colsByPos_));
+    public Column getByName(String name) {
+      return colsByName_.get(name.toLowerCase());
+    }
 
-      tableStats_ = new TTableStats(
-          FeCatalogUtils.getRowCount(msTable_.getParameters()));
-      tableStats_.setTotal_file_bytes(
-          FeCatalogUtils.getTotalSize(msTable_.getParameters()));
+    public int getNumClusteringCols() {
+      return numClusteringCols_;
     }
 
+
+    public List<Column> getNonClusteringColumns() {
+      return colsByPos_.subList(numClusteringCols_, colsByPos_.size());
+    }
+
+    public List<Column> getClusteringColumns() {
+      return colsByPos_.subList(0, numClusteringCols_);
+    }
+
+    public List<String> getColumnNames() {
+      return Column.toColumnNames(colsByPos_);
+    }
+
+
     private static StructType columnsToStructType(List<Column> cols) {
       ArrayList<StructField> fields = Lists.newArrayListWithCapacity(cols.size());
       for (Column col : cols) {
@@ -300,13 +325,9 @@ abstract class LocalTable implements FeTable {
       return builder.build();
     }
 
-    private boolean isClusteringColumn(Column c) {
+    boolean isClusteringColumn(Column c) {
       Preconditions.checkArgument(colsByPos_.get(c.getPosition()) == c);
       return c.getPosition() < numClusteringCols_;
     }
-
-    protected String getNullColumnValue() {
-      return nullColumnValue_;
-    }
   }
 }

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/catalog/local/LocalView.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/LocalView.java b/fe/src/main/java/org/apache/impala/catalog/local/LocalView.java
index c380eb1..1aecdd2 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/LocalView.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/LocalView.java
@@ -20,6 +20,7 @@ package org.apache.impala.catalog.local;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.hadoop.hive.metastore.api.Table;
 import org.apache.impala.analysis.QueryStmt;
 import org.apache.impala.catalog.FeView;
 import org.apache.impala.catalog.TableLoadingException;
@@ -36,8 +37,8 @@ import org.apache.impala.thrift.TTableDescriptor;
 public class LocalView extends LocalTable implements FeView {
   private final QueryStmt queryStmt_;
 
-  public LocalView(LocalDb db, String tblName, SchemaInfo schemaInfo) {
-    super(db, tblName, schemaInfo);
+  public LocalView(LocalDb db, Table msTbl) {
+    super(db, msTbl);
 
     try {
       queryStmt_ = View.parseViewDef(this);

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/planner/DistributedPlanner.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/DistributedPlanner.java b/fe/src/main/java/org/apache/impala/planner/DistributedPlanner.java
index ef24f6c..4302244 100644
--- a/fe/src/main/java/org/apache/impala/planner/DistributedPlanner.java
+++ b/fe/src/main/java/org/apache/impala/planner/DistributedPlanner.java
@@ -28,7 +28,7 @@ import org.apache.impala.analysis.InsertStmt;
 import org.apache.impala.analysis.JoinOperator;
 import static org.apache.impala.analysis.JoinOperator.*;
 import org.apache.impala.analysis.QueryStmt;
-import org.apache.impala.catalog.KuduTable;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.common.ImpalaException;
 import org.apache.impala.common.InternalException;
 import org.apache.impala.planner.JoinNode.DistributionMode;
@@ -202,13 +202,13 @@ public class DistributedPlanner {
     if (!partitionExprs.isEmpty()
         && analyzer.setsHaveValueTransfer(inputPartition.getPartitionExprs(),
         partitionExprs, true)
-        && !(insertStmt.getTargetTable() instanceof KuduTable)) {
+        && !(insertStmt.getTargetTable() instanceof FeKuduTable)) {
       return inputFragment;
     }
 
     // Make a cost-based decision only if no user hint was supplied.
     if (!insertStmt.hasShuffleHint()) {
-      if (insertStmt.getTargetTable() instanceof KuduTable) {
+      if (insertStmt.getTargetTable() instanceof FeKuduTable) {
         // If the table is unpartitioned or all of the partition exprs are constants,
         // don't insert the exchange.
         // TODO: make a more sophisticated decision here for partitioned tables and when
@@ -246,7 +246,7 @@ public class DistributedPlanner {
     DataPartition partition;
     if (partitionExprs.isEmpty()) {
       partition = DataPartition.UNPARTITIONED;
-    } else if (insertStmt.getTargetTable() instanceof KuduTable) {
+    } else if (insertStmt.getTargetTable() instanceof FeKuduTable) {
       partition = DataPartition.kuduPartitioned(
           KuduUtil.createPartitionExpr(insertStmt, ctx_.getRootAnalyzer()));
     } else {

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java b/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java
index f6d89ad..95b31a2 100644
--- a/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java
+++ b/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java
@@ -35,8 +35,8 @@ import org.apache.impala.analysis.SlotDescriptor;
 import org.apache.impala.analysis.SlotRef;
 import org.apache.impala.analysis.StringLiteral;
 import org.apache.impala.analysis.TupleDescriptor;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.KuduColumn;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.catalog.Type;
 import org.apache.impala.common.ImpalaRuntimeException;
 import org.apache.impala.thrift.TExplainLevel;
@@ -86,7 +86,7 @@ import com.google.common.collect.Sets;
 public class KuduScanNode extends ScanNode {
   private final static Logger LOG = LoggerFactory.getLogger(KuduScanNode.class);
 
-  private final KuduTable kuduTable_;
+  private final FeKuduTable kuduTable_;
 
   // True if this scan node should use the MT implementation in the backend.
   private boolean useMtScanNode_;
@@ -104,7 +104,7 @@ public class KuduScanNode extends ScanNode {
 
   public KuduScanNode(PlanNodeId id, TupleDescriptor desc, List<Expr> conjuncts) {
     super(id, desc, "SCAN KUDU");
-    kuduTable_ = (KuduTable) desc_.getTable();
+    kuduTable_ = (FeKuduTable) desc_.getTable();
     conjuncts_ = conjuncts;
   }
 

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/planner/Planner.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/Planner.java b/fe/src/main/java/org/apache/impala/planner/Planner.java
index 829325b..9948840 100644
--- a/fe/src/main/java/org/apache/impala/planner/Planner.java
+++ b/fe/src/main/java/org/apache/impala/planner/Planner.java
@@ -32,9 +32,9 @@ import org.apache.impala.analysis.JoinOperator;
 import org.apache.impala.analysis.QueryStmt;
 import org.apache.impala.analysis.SortInfo;
 import org.apache.impala.analysis.TupleId;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HBaseTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.common.ImpalaException;
 import org.apache.impala.common.PrintUtils;
 import org.apache.impala.common.RuntimeEnv;
@@ -184,7 +184,7 @@ public class Planner {
         List<Expr> exprs = Lists.newArrayList();
         FeTable targetTable = insertStmt.getTargetTable();
         Preconditions.checkNotNull(targetTable);
-        if (targetTable instanceof KuduTable) {
+        if (targetTable instanceof FeKuduTable) {
           if (ctx_.isInsert()) {
             // For insert statements on Kudu tables, we only need to consider
             // the labels of columns mentioned in the column list.
@@ -620,7 +620,7 @@ public class Planner {
     List<Expr> orderingExprs = Lists.newArrayList();
 
     boolean partialSort = false;
-    if (insertStmt.getTargetTable() instanceof KuduTable) {
+    if (insertStmt.getTargetTable() instanceof FeKuduTable) {
       // Always sort if the 'clustered' hint is present. Otherwise, don't sort if either
       // the 'noclustered' hint is present, or this is a single node exec, or if the
       // target table is unpartitioned.

http://git-wip-us.apache.org/repos/asf/impala/blob/c333b552/fe/src/main/java/org/apache/impala/planner/SingleNodePlanner.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/SingleNodePlanner.java b/fe/src/main/java/org/apache/impala/planner/SingleNodePlanner.java
index 9b7111f..45e2351 100644
--- a/fe/src/main/java/org/apache/impala/planner/SingleNodePlanner.java
+++ b/fe/src/main/java/org/apache/impala/planner/SingleNodePlanner.java
@@ -56,9 +56,9 @@ import org.apache.impala.catalog.ColumnStats;
 import org.apache.impala.catalog.FeDataSourceTable;
 import org.apache.impala.catalog.FeFsPartition;
 import org.apache.impala.catalog.FeFsTable;
+import org.apache.impala.catalog.FeKuduTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HBaseTable;
-import org.apache.impala.catalog.KuduTable;
 import org.apache.impala.catalog.Type;
 import org.apache.impala.common.ImpalaException;
 import org.apache.impala.common.InternalException;
@@ -1311,7 +1311,7 @@ public class SingleNodePlanner {
     } else if (table instanceof HBaseTable) {
       // HBase table
       scanNode = new HBaseScanNode(ctx_.getNextNodeId(), tblRef.getDesc());
-    } else if (tblRef.getTable() instanceof KuduTable) {
+    } else if (tblRef.getTable() instanceof FeKuduTable) {
       scanNode = new KuduScanNode(ctx_.getNextNodeId(), tblRef.getDesc(), conjuncts);
       scanNode.init(analyzer);
       return scanNode;