KYLIN-2743 Potential corrupt TableDesc when loading an existing Hive table
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/fdf13892 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/fdf13892 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/fdf13892 Branch: refs/heads/2.1.x Commit: fdf13892b4177a0157a5cf1621db0e3a662bfd30 Parents: adcd0b6 Author: Yang Li <liy...@apache.org> Authored: Sun Jul 16 10:12:38 2017 +0800 Committer: Yang Li <liy...@apache.org> Committed: Sun Jul 16 12:36:22 2017 +0800 ---------------------------------------------------------------------- .../java/org/apache/kylin/metadata/model/TableDesc.java | 9 ++++++++- .../apache/kylin/source/hive/HiveMetadataExplorer.java | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/fdf13892/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java ---------------------------------------------------------------------- diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java index b388f11..530732a 100644 --- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java +++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java @@ -61,16 +61,23 @@ public class TableDesc extends RootPersistentEntity implements ISourceAware { } public TableDesc(TableDesc other) { + this.uuid = other.uuid; + this.lastModified = other.lastModified; + this.name = other.name; this.sourceType = other.sourceType; - this.database.setName(other.getDatabase()); this.tableType = other.tableType; this.dataGen = other.dataGen; + this.columns = new ColumnDesc[other.columns.length]; for (int i = 0; i < other.columns.length; i++) { this.columns[i] = new ColumnDesc(other.columns[i]); this.columns[i].init(this); } + + this.project = other.project; + this.database.setName(other.getDatabase()); + this.identity = other.identity; } public TableDesc appendColumns(ColumnDesc[] computedColumns) { http://git-wip-us.apache.org/repos/asf/kylin/blob/fdf13892/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java ---------------------------------------------------------------------- diff --git a/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java b/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java index 0db4b40..00a1c3b 100644 --- a/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java +++ b/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java @@ -59,13 +59,18 @@ public class HiveMetadataExplorer implements ISourceMetadataExplorer, ISampleDat } TableDesc tableDesc = metaMgr.getTableDesc(database + "." + tableName); + + // make a new TableDesc instance, don't modify the one in use if (tableDesc == null) { tableDesc = new TableDesc(); tableDesc.setDatabase(database.toUpperCase()); tableDesc.setName(tableName.toUpperCase()); tableDesc.setUuid(UUID.randomUUID().toString()); tableDesc.setLastModified(0); + } else { + tableDesc = new TableDesc(tableDesc); } + if (hiveTableMeta.tableType != null) { tableDesc.setTableType(hiveTableMeta.tableType); } @@ -95,7 +100,11 @@ public class HiveMetadataExplorer implements ISourceMetadataExplorer, ISampleDat partitionColumnString.append(hiveTableMeta.partitionColumns.get(i).name.toUpperCase()); } - TableExtDesc tableExtDesc = metaMgr.getTableExt(tableDesc.getIdentity()); + TableExtDesc tableExtDesc = new TableExtDesc(); + tableExtDesc.setName(tableDesc.getIdentity()); + tableExtDesc.setUuid(UUID.randomUUID().toString()); + tableExtDesc.setLastModified(0); + tableExtDesc.addDataSourceProp("location", hiveTableMeta.sdLocation); tableExtDesc.addDataSourceProp("owner", hiveTableMeta.owner); tableExtDesc.addDataSourceProp("last_access_time", String.valueOf(hiveTableMeta.lastAccessTime));