You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by pr...@apache.org on 2015/02/02 12:14:52 UTC
[2/5] incubator-lens git commit: LENS-236: Cube.xsd cleanup
(amareshwari via prongs)
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/a4f18620/lens-examples/src/main/resources/sample-dimension.xml
----------------------------------------------------------------------
diff --git a/lens-examples/src/main/resources/sample-dimension.xml b/lens-examples/src/main/resources/sample-dimension.xml
index 7f650fc..1f7af3c 100644
--- a/lens-examples/src/main/resources/sample-dimension.xml
+++ b/lens-examples/src/main/resources/sample-dimension.xml
@@ -1,40 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- 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
+ 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
+ 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.
+ 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.
-->
-<x_dimension name="sample_dim"
- xmlns="uri:lens:cube:0.1"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<x_dimension name="sample_dim" xmlns="uri:lens:cube:0.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="uri:lens:cube:0.1 cube-0.1.xsd ">
<attributes>
- <dim_attributes name="id" type="int"/>
- <dim_attributes name="name" type="string" />
- <dim_attributes name="detail" type="string" start_time='2013-12-01-00:00'/>
- <dim_attributes name="d2id" type="int" start_time='2013-12-01-00:00'>
- <references>
- <table_references dest_table="sample_dim2" dest_column="id"/>
- </references>
- </dim_attributes>
+ <dim_attribute name="id" type="INT" />
+ <dim_attribute name="name" type="STRING" />
+ <dim_attribute name="detail" type="STRING" start_time='2013-12-01-00:00' />
+ <dim_attribute name="d2id" type="INT" start_time='2013-12-01-00:00'>
+ <ref_spec>
+ <table_references>
+ <table_reference table="sample_dim2" column="id" />
+ </table_references>
+ </ref_spec>
+ </dim_attribute>
</attributes>
<properties>
- <properties name="sample_dim.prop" value="sample" />
- <properties name="dimension.sample_dim.timed.dimension" value="dt" />
+ <property name="dimension.sample_dim.timed.dimension" value="dt" />
</properties>
</x_dimension>
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/a4f18620/lens-examples/src/main/resources/sample-dimension2.xml
----------------------------------------------------------------------
diff --git a/lens-examples/src/main/resources/sample-dimension2.xml b/lens-examples/src/main/resources/sample-dimension2.xml
index 3ae8797..fd9a2ca 100644
--- a/lens-examples/src/main/resources/sample-dimension2.xml
+++ b/lens-examples/src/main/resources/sample-dimension2.xml
@@ -1,35 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- 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
+ 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
+ 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.
+ 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.
-->
-<x_dimension name="sample_dim2"
- xmlns="uri:lens:cube:0.1"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<x_dimension name="sample_dim2" xmlns="uri:lens:cube:0.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="uri:lens:cube:0.1 cube-0.1.xsd ">
<attributes>
- <dim_attributes name="id" type="int"/>
- <dim_attributes name="name" type="string" />
- <dim_attributes name="detail2" type="string" start_time='2013-12-01-00:00'/>
+ <dim_attribute name="id" type="INT" />
+ <dim_attribute name="name" type="STRING" />
+ <dim_attribute name="detail2" type="STRING" start_time='2013-12-01-00:00' />
</attributes>
<properties>
- <properties name="sample_dim2.prop" value="sample" />
- <properties name="dimension.sample_dim2.timed.dimension" value="dt" />
+ <property name="dimension.sample_dim2.timed.dimension" value="dt" />
</properties>
</x_dimension>
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/a4f18620/lens-server-api/src/main/java/org/apache/lens/server/api/metastore/CubeMetastoreService.java
----------------------------------------------------------------------
diff --git a/lens-server-api/src/main/java/org/apache/lens/server/api/metastore/CubeMetastoreService.java b/lens-server-api/src/main/java/org/apache/lens/server/api/metastore/CubeMetastoreService.java
index 1acab08..fd377ea 100644
--- a/lens-server-api/src/main/java/org/apache/lens/server/api/metastore/CubeMetastoreService.java
+++ b/lens-server-api/src/main/java/org/apache/lens/server/api/metastore/CubeMetastoreService.java
@@ -27,7 +27,10 @@ import org.apache.lens.api.metastore.*;
import org.apache.hadoop.hive.ql.metadata.HiveException;
-
+/**
+ * Server api for OLAP Cube Metastore.
+ *
+ */
public interface CubeMetastoreService {
/**
* Get current database used by the CubeMetastoreClient
@@ -149,7 +152,7 @@ public interface CubeMetastoreService {
* @return {@link NativeTable} object
* @throws LensException
*/
- NativeTable getNativeTable(LensSessionHandle sessionid, String name) throws LensException;
+ XNativeTable getNativeTable(LensSessionHandle sessionid, String name) throws LensException;
/**
* Get names of all native tables
@@ -227,9 +230,14 @@ public interface CubeMetastoreService {
throws LensException;
/**
- * Create a cube dimension table
+ * Create dimension table
+ *
+ * @param sessionid The sessionid
+ * @param xDimTable The dim table definition
+ *
+ * @throws LensException
*/
- void createCubeDimensionTable(LensSessionHandle sessionid, DimensionTable xDimTable, XStorageTables storageTables)
+ void createDimensionTable(LensSessionHandle sessionid, XDimensionTable xDimTable)
throws LensException;
/**
@@ -248,27 +256,104 @@ public interface CubeMetastoreService {
* @param dimTblName
* @return The {@link DimensionTable}
*/
- DimensionTable getDimensionTable(LensSessionHandle sessionid, String dimTblName) throws LensException;
+ XDimensionTable getDimensionTable(LensSessionHandle sessionid, String dimTblName) throws LensException;
- void updateDimensionTable(LensSessionHandle sessionid, DimensionTable dimensionTable) throws LensException;
+ /**
+ * Update/Alter the dimension table
+ *
+ * @param sessionid The sessionid
+ * @param dimensionTable The new definition of dimension table
+ *
+ * @throws LensException
+ */
+ void updateDimensionTable(LensSessionHandle sessionid, XDimensionTable dimensionTable) throws LensException;
+ /**
+ * Get all storages of dimension table
+ *
+ * @param sessionid The sessionid
+ * @param dimTblName The dimension table name
+ *
+ * @return list of storage names
+ * @throws LensException
+ */
List<String> getDimTableStorages(LensSessionHandle sessionid, String dimTblName) throws LensException;
- void createDimTableStorage(LensSessionHandle sessionid, String dimTblName, XStorageTableElement storageTable)
+ /**
+ * Add a storage to dimension table
+ *
+ * @param sessionid The sessionid
+ * @param dimTblName The dimension table name
+ * @param storageTable XStorageTableElement with storage name, table desc and dump period, if any.
+ *
+ * @throws LensException
+ */
+ void addDimTableStorage(LensSessionHandle sessionid, String dimTblName, XStorageTableElement storageTable)
throws LensException;
+ /**
+ * Drop all storages of dimension table. Will drop underlying tables as well.
+ *
+ * @param sessionid The sessionid
+ * @param dimTblName The dimension table name
+ *
+ * @throws LensException
+ */
void dropAllStoragesOfDimTable(LensSessionHandle sessionid, String dimTblName) throws LensException;
+ /**
+ * Get storage table element associated with dimension table for storage name specified
+ *
+ * @param sessionid The sessionid
+ * @param dimTblName The dimension table name
+ * @param storageName The storage name
+ * @return {@link XStorageTableElement}
+ * @throws LensException
+ */
XStorageTableElement getStorageOfDim(LensSessionHandle sessionid, String dimTblName, String storageName)
throws LensException;
+ /**
+ * Drop storage of dimension table specified by name.
+ *
+ * @param sessionid The sessionid
+ * @param dimTblName The dimension table name
+ * @param storageName The storage name
+ * @throws LensException
+ */
void dropStorageOfDimTable(LensSessionHandle sessionid, String dimTblName, String storage) throws LensException;
+ /**
+ * Get all dimension tables
+ *
+ * @param sessionid
+ * @return
+ * @throws LensException
+ */
List<String> getAllDimTableNames(LensSessionHandle sessionid) throws LensException;
+ /**
+ * Get all partitions of a dimension table in a storage
+ *
+ * @param sessionid The sessionid
+ * @param dimTblName The dimension table name
+ * @param storageName The storage name
+ * @param filter The filter for the list of partitions
+ * @return list of {@link XPartition}
+ * @throws LensException
+ */
List<XPartition> getAllPartitionsOfDimTableStorage(LensSessionHandle sessionid, String dimTblName,
String storage, String filter) throws LensException;
+ /**
+ * Add partition to dimension table on a storage.
+ *
+ * @param sessionid The sessionid
+ * @param dimTblName The dimension table name
+ * @param storageName The storage name
+ * @param partition {@link XPartition}
+ * @throws LensException
+ */
void addPartitionToDimStorage(LensSessionHandle sessionid, String dimTblName, String storageName,
XPartition partition) throws LensException;
@@ -280,47 +365,178 @@ public interface CubeMetastoreService {
* @return List of FactTable objects
* @throws LensException
*/
- List<FactTable> getAllFactsOfCube(LensSessionHandle sessionid, String cubeName) throws LensException;
+ List<XFactTable> getAllFactsOfCube(LensSessionHandle sessionid, String cubeName) throws LensException;
- FactTable getFactTable(LensSessionHandle sessionid, String fact) throws LensException;
+ /**
+ * Get fact table given by name
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table name
+ *
+ * @return {@link FactTable}
+ * @throws LensException
+ */
+ XFactTable getFactTable(LensSessionHandle sessionid, String fact) throws LensException;
- void createFactTable(LensSessionHandle sessionid, FactTable fact, XStorageTables storageTables) throws LensException;
+ /**
+ * Create fact table
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table definition
+ *
+ * @throws LensException
+ */
+ void createFactTable(LensSessionHandle sessionid, XFactTable fact) throws LensException;
- void updateFactTable(LensSessionHandle sessionid, FactTable fact) throws LensException;
+ /**
+ * Update/Alter fact table
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table's new definition
+ *
+ * @throws LensException
+ */
+ void updateFactTable(LensSessionHandle sessionid, XFactTable fact) throws LensException;
+ /**
+ * Drop fact table.
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table name
+ * @param cascade If true, underlying storage tables will also be dropped.
+ *
+ * @throws LensException
+ */
void dropFactTable(LensSessionHandle sessionid, String fact, boolean cascade) throws LensException;
+ /**
+ * Get all fact names
+ *
+ * @param sessionid The sessionid
+ * @return List of fact table names
+ *
+ * @throws LensException
+ */
List<String> getAllFactNames(LensSessionHandle sessionid) throws LensException;
+ /**
+ * Get all storages of fact
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table name
+ *
+ * @return List of all storage names on which fact is present
+ * @throws LensException
+ */
List<String> getStoragesOfFact(LensSessionHandle sessionid, String fact) throws LensException;
+ /**
+ * Drop all storages of fact
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table name
+ *
+ * @throws LensException
+ */
void dropAllStoragesOfFact(LensSessionHandle sessionid, String factName) throws LensException;
+ /**
+ * Get storage table of fact specifed by fact name, storage name
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table name
+ * @param storageName The storage name
+ * @return
+ * @throws LensException
+ */
XStorageTableElement getStorageOfFact(LensSessionHandle sessionid, String fact, String storageName)
throws LensException;
+ /**
+ * Add storage to fact table
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table name
+ * @param storageTable XStorageTableElement containing storage name, update periods and table description
+ * @throws LensException
+ */
void addStorageToFact(LensSessionHandle sessionid, String fact, XStorageTableElement storageTable)
throws LensException;
+ /**
+ * Drop storage of fact specified by fact name, storage name
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table name
+ * @param storageName The storage name
+ *
+ * @throws LensException
+ */
void dropStorageOfFact(LensSessionHandle sessionid, String fact, String storage) throws LensException;
+ /**
+ * Get all partitions of fact on a storage
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table name
+ * @param storageName The storage name
+ * @param filter The filter for partition listing
+ *
+ * @return List of {@link XPartition}
+ * @throws LensException
+ */
List<XPartition> getAllPartitionsOfFactStorage(LensSessionHandle sessionid, String fact,
String storage, String filter) throws LensException;
+ /**
+ * Add partition to fact on a storage
+ *
+ * @param sessionid The sessionid
+ * @param fact The fact table name
+ * @param storageName The storage name
+ * @param partition {@link XPartition}
+ *
+ * @throws LensException
+ */
void addPartitionToFactStorage(LensSessionHandle sessionid, String fact, String storageName, XPartition partition)
throws LensException;
- void dropPartitionFromStorage(LensSessionHandle sessionid,
- String cubeTableName, String storageName, XTimePartSpec timePartSpec,
- XPartSpec nonTimePartSpec, String updatePeriod) throws LensException;
-
+ /**
+ * Drop partition from storage with spec specified as comma separated string
+ *
+ * @param sessionid The sessionid
+ * @param cubeTableName The cube table name - fact/dimension table name
+ * @param storageName The storage name
+ * @param values The comma separated values for all partition columns
+ *
+ * @throws LensException
+ */
void dropPartitionFromStorageByValues(LensSessionHandle sessionid,
String cubeTableName, String storageName, String values) throws LensException;
+ /**
+ * Drop partition from storage with spec specified by filter
+ *
+ * @param sessionid The sessionid
+ * @param cubeTableName The cube table name - fact/dimension table name
+ * @param storageName The storage name
+ * @param filter The partition filter - all partitions which obey the filter will be dropped
+ *
+ * @throws LensException
+ */
void dropPartitionFromStorageByFilter(LensSessionHandle sessionid,
String cubeTableName, String storageName, String filter) throws LensException;
- FlattenedColumns getFlattenedColumns(LensSessionHandle sessionHandle, String tableName) throws LensException;
+ /**
+ * Get flattened columns - all columns of table + all reachable columns
+ *
+ * @param sessionid The sessionid
+ * @param tableName The table name - cube name or dimension name
+ *
+ * @return {@link FlattenedColumns}
+ * @throws LensException
+ */
+ XFlattenedColumns getFlattenedColumns(LensSessionHandle sessionHandle, String tableName) throws LensException;
/**
* Get the latest available date upto which data is available for the base cubes, for the time dimension
@@ -328,6 +544,7 @@ public interface CubeMetastoreService {
* @param sessionid The session id
* @param timeDimension time dimension name
* @param cubeName The base cube name
+ *
* @return Date
* @throws LensException,HiveException
*/
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/a4f18620/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java b/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java
index 0275fba..0b63232 100644
--- a/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java
+++ b/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java
@@ -186,7 +186,8 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
public void createCube(LensSessionHandle sessionid, XCube cube) throws LensException {
try {
acquire(sessionid);
- Cube parent = cube.isDerived() ? (Cube) getClient(sessionid).getCube(cube.getParent()) : null;
+ Cube parent = cube instanceof XDerivedCube ? (Cube) getClient(sessionid).getCube(
+ ((XDerivedCube)cube).getParent()) : null;
getClient(sessionid).createCube(JAXBUtils.hiveCubeFromXCube(cube, parent));
LOG.info("Created cube " + cube.getName());
} catch (HiveException e) {
@@ -248,7 +249,8 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
public void updateCube(LensSessionHandle sessionid, XCube cube) throws LensException {
try {
acquire(sessionid);
- Cube parent = cube.isDerived() ? (Cube) getClient(sessionid).getCube(cube.getParent()) : null;
+ Cube parent = cube instanceof XDerivedCube ? (Cube) getClient(sessionid).getCube(
+ ((XDerivedCube)cube).getParent()) : null;
getClient(sessionid).alterCube(cube.getName(), JAXBUtils.hiveCubeFromXCube(cube, parent));
LOG.info("Cube updated " + cube.getName());
} catch (HiveException e) {
@@ -267,19 +269,20 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
* @throws LensException
*/
@Override
- public void createCubeDimensionTable(LensSessionHandle sessionid, DimensionTable xDimTable, XStorageTables storageTables) throws LensException {
+ public void createDimensionTable(LensSessionHandle sessionid, XDimensionTable xDimTable) throws LensException {
String dimTblName = xDimTable.getTableName();
List<FieldSchema> columns = JAXBUtils.fieldSchemaListFromColumns(xDimTable.getColumns());
Map<String, UpdatePeriod> updatePeriodMap =
- JAXBUtils.dumpPeriodsFromUpdatePeriods(xDimTable.getStorageDumpPeriods());
+ JAXBUtils.dumpPeriodsFromStorageTables(xDimTable.getStorageTables());
Map<String, String> properties = JAXBUtils.mapFromXProperties(xDimTable.getProperties());
- Map<String, StorageTableDesc> storageDesc = JAXBUtils.storageTableMapFromXStorageTables(storageTables);
+ Map<String, StorageTableDesc> storageDesc = JAXBUtils.storageTableMapFromXStorageTables(
+ xDimTable.getStorageTables());
try {
acquire(sessionid);
LOG.info("# Columns: " + columns);
- getClient(sessionid).createCubeDimensionTable(xDimTable.getDimName(),
+ getClient(sessionid).createCubeDimensionTable(xDimTable.getDimensionName(),
dimTblName,
columns,
xDimTable.getWeight(),
@@ -309,11 +312,22 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
@Override
- public DimensionTable getDimensionTable(LensSessionHandle sessionid, String dimTblName) throws LensException {
+ public XDimensionTable getDimensionTable(LensSessionHandle sessionid, String dimTblName) throws LensException {
try {
acquire(sessionid);
- CubeDimensionTable cubeDimTable = getClient(sessionid).getDimensionTable(dimTblName);
- return JAXBUtils.dimTableFromCubeDimTable(cubeDimTable);
+ CubeDimensionTable dimTable = getClient(sessionid).getDimensionTable(dimTblName);
+ XDimensionTable dt = JAXBUtils.dimTableFromCubeDimTable(dimTable);
+ for (String storageName : dimTable.getStorages()) {
+ XStorageTableElement tblElement = JAXBUtils.getXStorageTableFromHiveTable(
+ getClient(sessionid).getHiveTable(MetastoreUtil.getDimStorageTableName(dimTblName, storageName)));
+ tblElement.setStorageName(storageName);
+ UpdatePeriod p = dimTable.getSnapshotDumpPeriods().get(storageName);
+ if (p != null) {
+ tblElement.getUpdatePeriods().getUpdatePeriod().add(XUpdatePeriod.valueOf(p.name()));
+ }
+ dt.getStorageTables().getStorageTable().add(tblElement);
+ }
+ return dt;
} catch (HiveException exc) {
throw new LensException(exc);
} finally {
@@ -322,11 +336,12 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
@Override
- public void updateDimensionTable(LensSessionHandle sessionid, DimensionTable dimensionTable) throws LensException {
+ public void updateDimensionTable(LensSessionHandle sessionid, XDimensionTable dimensionTable) throws LensException {
try {
acquire(sessionid);
getClient(sessionid).alterCubeDimensionTable(dimensionTable.getTableName(),
JAXBUtils.cubeDimTableFromDimTable(dimensionTable));
+ // TODO alter storage tables
LOG.info("Updated dimension table " + dimensionTable.getTableName());
} catch (HiveException exc) {
throw new LensException(exc);
@@ -350,14 +365,14 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
@Override
- public void createDimTableStorage(LensSessionHandle sessionid,
+ public void addDimTableStorage(LensSessionHandle sessionid,
String dimTblName, XStorageTableElement storageTable) throws LensException {
try {
acquire(sessionid);
CubeDimensionTable dimTable = getClient(sessionid).getDimensionTable(dimTblName);
UpdatePeriod period = null;
- if (!storageTable.getUpdatePeriods().isEmpty()) {
- period = UpdatePeriod.valueOf(storageTable.getUpdatePeriods().get(0).toUpperCase());
+ if (storageTable.getUpdatePeriods() != null && !storageTable.getUpdatePeriods().getUpdatePeriod().isEmpty()) {
+ period = UpdatePeriod.valueOf(storageTable.getUpdatePeriods().getUpdatePeriod().get(0).name());
}
getClient(sessionid).addStorage(dimTable, storageTable.getStorageName(), period,
JAXBUtils.storageTableDescFromXStorageTableDesc(storageTable.getTableDesc()));
@@ -431,12 +446,12 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
@Override
- public List<FactTable> getAllFactsOfCube(LensSessionHandle sessionid, String cubeName) throws LensException {
+ public List<XFactTable> getAllFactsOfCube(LensSessionHandle sessionid, String cubeName) throws LensException {
try {
acquire(sessionid);
List<CubeFactTable> cubeFacts = getClient(sessionid).getAllFactTables(getClient(sessionid).getCube(cubeName));
if (cubeFacts != null && !cubeFacts.isEmpty()) {
- List<FactTable> facts = new ArrayList<FactTable>(cubeFacts.size());
+ List<XFactTable> facts = new ArrayList<XFactTable>(cubeFacts.size());
for (CubeFactTable cft : cubeFacts) {
facts.add(JAXBUtils.factTableFromCubeFactTable(cft));
}
@@ -451,10 +466,22 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
@Override
- public FactTable getFactTable(LensSessionHandle sessionid, String fact) throws LensException {
+ public XFactTable getFactTable(LensSessionHandle sessionid, String fact) throws LensException {
try {
acquire(sessionid);
- return JAXBUtils.factTableFromCubeFactTable(getClient(sessionid).getFactTable(fact));
+ CubeFactTable cft = getClient(sessionid).getFactTable(fact);
+ XFactTable factTable = JAXBUtils.factTableFromCubeFactTable(cft);
+ for (String storageName : cft.getStorages()) {
+ Set<UpdatePeriod> updatePeriods = cft.getUpdatePeriods().get(storageName);
+ XStorageTableElement tblElement = JAXBUtils.getXStorageTableFromHiveTable(
+ getClient(sessionid).getHiveTable(MetastoreUtil.getFactStorageTableName(fact, storageName)));
+ tblElement.setStorageName(storageName);
+ for (UpdatePeriod p : updatePeriods) {
+ tblElement.getUpdatePeriods().getUpdatePeriod().add(XUpdatePeriod.valueOf(p.name()));
+ }
+ factTable.getStorageTables().getStorageTable().add(tblElement);
+ }
+ return factTable;
} catch (HiveException e) {
throw new LensException(e);
} finally {
@@ -463,16 +490,16 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
@Override
- public void createFactTable(LensSessionHandle sessionid, FactTable fact, XStorageTables storageTables) throws LensException {
+ public void createFactTable(LensSessionHandle sessionid, XFactTable fact) throws LensException {
try {
acquire(sessionid);
getClient(sessionid).createCubeFactTable(fact.getCubeName(),
fact.getName(),
JAXBUtils.fieldSchemaListFromColumns(fact.getColumns()),
- JAXBUtils.getFactUpdatePeriodsFromUpdatePeriods(fact.getStorageUpdatePeriods()),
+ JAXBUtils.getFactUpdatePeriodsFromStorageTables(fact.getStorageTables()),
fact.getWeight(),
JAXBUtils.mapFromXProperties(fact.getProperties()),
- JAXBUtils.storageTableMapFromXStorageTables(storageTables));
+ JAXBUtils.storageTableMapFromXStorageTables(fact.getStorageTables()));
LOG.info("Created fact table " + fact.getName());
} catch (HiveException e) {
throw new LensException(e);
@@ -482,10 +509,11 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
@Override
- public void updateFactTable(LensSessionHandle sessionid, FactTable fact) throws LensException {
+ public void updateFactTable(LensSessionHandle sessionid, XFactTable fact) throws LensException {
try {
acquire(sessionid);
getClient(sessionid).alterCubeFactTable(fact.getName(), JAXBUtils.cubeFactFromFactTable(fact));
+ // TODO alter storage tables
LOG.info("Updated fact table " + fact.getName());
} catch (HiveException e) {
throw new LensException(e);
@@ -570,7 +598,7 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
getClient(sessionid).getHiveTable(MetastoreUtil.getFactStorageTableName(fact, storageName)));
tblElement.setStorageName(storageName);
for (UpdatePeriod p : updatePeriods) {
- tblElement.getUpdatePeriods().add(p.name());
+ tblElement.getUpdatePeriods().getUpdatePeriod().add(XUpdatePeriod.valueOf(p.name()));
}
return tblElement;
} catch (HiveException exc) {
@@ -588,7 +616,7 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
tblElement.setStorageName(storageName);
UpdatePeriod p = dimTable.getSnapshotDumpPeriods().get(storageName);
if (p != null) {
- tblElement.getUpdatePeriods().add(p.name());
+ tblElement.getUpdatePeriods().getUpdatePeriod().add(XUpdatePeriod.valueOf(p.name()));
}
return tblElement;
} catch (HiveException exc) {
@@ -601,8 +629,8 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
@Override
public void addStorageToFact(LensSessionHandle sessionid, String fact, XStorageTableElement storageTable) throws LensException {
Set<UpdatePeriod> updatePeriods = new TreeSet<UpdatePeriod>();
- for (String sup : storageTable.getUpdatePeriods()) {
- updatePeriods.add(UpdatePeriod.valueOf(sup.toUpperCase()));
+ for (XUpdatePeriod sup : storageTable.getUpdatePeriods().getUpdatePeriod()) {
+ updatePeriods.add(UpdatePeriod.valueOf(sup.name()));
}
try {
acquire(sessionid);
@@ -676,7 +704,7 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
XPartition partition) throws LensException {
try {
acquire(sessionid);
- CubeFactTable factTable = checkFactStorage(sessionid, fact, storageName);
+ checkFactStorage(sessionid, fact, storageName);
getClient(sessionid).addPartition(
JAXBUtils.storagePartSpecFromXPartition(partition),
storageName);
@@ -735,7 +763,7 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
String dimTblName, String storageName, XPartition partition) throws LensException {
try {
acquire(sessionid);
- CubeDimensionTable dim = checkDimensionStorage(sessionid, dimTblName, storageName);
+ checkDimensionStorage(sessionid, dimTblName, storageName);
getClient(sessionid).addPartition(
JAXBUtils.storagePartSpecFromXPartition(partition),
storageName);
@@ -747,27 +775,6 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
}
- @Override
- public void dropPartitionFromStorage(LensSessionHandle sessionid,
- String cubeTableName, String storageName, XTimePartSpec timePartSpec,
- XPartSpec nonTimePartSpec, String updatePeriod) throws LensException {
- try {
- acquire(sessionid);
- checkDimensionStorage(sessionid, cubeTableName, storageName);
- getClient(sessionid).dropPartition(cubeTableName,
- storageName,
- JAXBUtils.timePartSpecfromXTimePartSpec(timePartSpec),
- JAXBUtils.nonTimePartSpecfromXNonTimePartSpec(nonTimePartSpec),
- UpdatePeriod.valueOf(updatePeriod.toUpperCase()));
- LOG.info("Dropped partition for dimension: " + cubeTableName +
- "storage: " + storageName + " partition:" + timePartSpec + " " + nonTimePartSpec);
- } catch (HiveException exc) {
- throw new LensException(exc);
- } finally {
- release(sessionid);
- }
- }
-
private String getFilter(CubeMetastoreClient client, String tableName,
String values) throws HiveException {
List<FieldSchema> cols = client.getHiveTable(tableName).getPartCols();
@@ -1107,7 +1114,7 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
@Override
- public NativeTable getNativeTable(LensSessionHandle sessionid, String name)
+ public XNativeTable getNativeTable(LensSessionHandle sessionid, String name)
throws LensException {
try {
acquire(sessionid);
@@ -1191,9 +1198,9 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
private void addAllMeasuresToFlattenedList(ObjectFactory objectFactory, CubeInterface cube,
- List<FlattenedColumn> columnList) {
+ List<XFlattenedColumn> columnList) {
for (CubeMeasure msr : cube.getMeasures()) {
- FlattenedColumn fcol = objectFactory.createFlattenedColumn();
+ XFlattenedColumn fcol = objectFactory.createXFlattenedColumn();
fcol.setMeasure(JAXBUtils.xMeasureFromHiveMeasure(msr));
fcol.setTableName(cube.getName());
columnList.add(fcol);
@@ -1201,11 +1208,11 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
private void addAllDirectAttributesToFlattenedListFromCube(ObjectFactory objectFactory, CubeInterface cube,
- List<FlattenedColumn> columnList) {
+ List<XFlattenedColumn> columnList) {
AbstractBaseTable baseTbl = (AbstractBaseTable)(cube instanceof DerivedCube ?
((DerivedCube)cube).getParent() : cube);
for (CubeDimAttribute dim : cube.getDimAttributes()) {
- FlattenedColumn fcol = objectFactory.createFlattenedColumn();
+ XFlattenedColumn fcol = objectFactory.createXFlattenedColumn();
fcol.setDimAttribute(JAXBUtils.xDimAttrFromHiveDimAttr(dim, baseTbl));
fcol.setTableName(cube.getName());
columnList.add(fcol);
@@ -1213,9 +1220,9 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
private void addAllDirectAttributesToFlattenedListFromDimension(ObjectFactory objectFactory, Dimension dimension,
- List<FlattenedColumn> columnList, String chainName) {
+ List<XFlattenedColumn> columnList, String chainName) {
for (CubeDimAttribute cd : dimension.getAttributes()) {
- FlattenedColumn fcol = objectFactory.createFlattenedColumn();
+ XFlattenedColumn fcol = objectFactory.createXFlattenedColumn();
fcol.setDimAttribute(JAXBUtils.xDimAttrFromHiveDimAttr(cd, dimension));
fcol.setTableName(dimension.getName());
if (chainName != null) {
@@ -1226,9 +1233,9 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
private void addAllDirectExpressionsToFlattenedList(ObjectFactory objectFactory, AbstractBaseTable baseTbl,
- List<FlattenedColumn> columnList, String chainName) {
+ List<XFlattenedColumn> columnList, String chainName) {
for (ExprColumn expr : baseTbl.getExpressions()) {
- FlattenedColumn fcol = objectFactory.createFlattenedColumn();
+ XFlattenedColumn fcol = objectFactory.createXFlattenedColumn();
fcol.setExpression(JAXBUtils.xExprColumnFromHiveExprColumn(expr));
fcol.setTableName(baseTbl.getName());
if (chainName != null) {
@@ -1239,7 +1246,7 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
private void addAllChainedColsToFlattenedListFromCube(CubeMetastoreClient client, ObjectFactory objectFactory,
- CubeInterface cube, List<FlattenedColumn> columnList) throws HiveException {
+ CubeInterface cube, List<XFlattenedColumn> columnList) throws HiveException {
if (cube instanceof DerivedCube) {
return;
}
@@ -1247,7 +1254,7 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
private void addAllChainedColsToFlattenedList(CubeMetastoreClient client, ObjectFactory objectFactory,
- AbstractBaseTable baseTbl, List<FlattenedColumn> columnList) throws HiveException {
+ AbstractBaseTable baseTbl, List<XFlattenedColumn> columnList) throws HiveException {
for (JoinChain chain : baseTbl.getJoinChains()) {
Dimension dim = client.getDimension(chain.getDestTable());
addAllDirectAttributesToFlattenedListFromDimension(objectFactory, dim, columnList, chain.getName());
@@ -1256,14 +1263,14 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
}
@Override
- public FlattenedColumns getFlattenedColumns(LensSessionHandle sessionHandle, String tableName) throws LensException {
+ public XFlattenedColumns getFlattenedColumns(LensSessionHandle sessionHandle, String tableName) throws LensException {
try {
acquire(sessionHandle);
CubeMetastoreClient client = getClient(sessionHandle);
ObjectFactory objectFactory = new ObjectFactory();
- FlattenedColumns flattenedColumns = objectFactory.createFlattenedColumns();
- List<FlattenedColumn> columnList = flattenedColumns.getFlattenedColumn();
+ XFlattenedColumns flattenedColumns = objectFactory.createXFlattenedColumns();
+ List<XFlattenedColumn> columnList = flattenedColumns.getFlattenedColumn();
// check if the table is a cube or dimension
if (client.isCube(tableName)) {
CubeInterface cube = client.getCube(tableName);
@@ -1304,11 +1311,11 @@ public class CubeMetastoreServiceImpl extends LensService implements CubeMetasto
// getting all facts->storages->partitions and iterating over them to get
// latest date
- List<FactTable> factTables = getAllFactsOfCube(sessionid, cubeName);
+ List<XFactTable> factTables = getAllFactsOfCube(sessionid, cubeName);
Date latestDate = null;
if (factTables != null && !factTables.isEmpty()) {
- for (FactTable factTable : factTables) {
+ for (XFactTable factTable : factTables) {
List<String> storages = getStoragesOfFact(sessionid, factTable.getName());
if (storages != null && !storages.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/a4f18620/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java b/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java
index e62dfed..329d899 100644
--- a/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java
+++ b/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java
@@ -39,7 +39,6 @@ import javax.xml.datatype.XMLGregorianCalendar;
import java.lang.reflect.Constructor;
import java.util.*;
-import java.util.Map.Entry;
/**
* Utilities for converting to and from JAXB types to hive.ql.metadata.cube types
@@ -57,44 +56,46 @@ public class JAXBUtils {
* @throws ParseException
*/
public static CubeInterface hiveCubeFromXCube(XCube cube, Cube parent) throws ParseException {
- if (cube.isDerived()) {
+ if (cube instanceof XDerivedCube) {
+ XDerivedCube dcube = (XDerivedCube)cube;
Set<String> dims = new LinkedHashSet<String>();
- dims.addAll(cube.getDimAttrNames().getDimAttrNames());
+ dims.addAll(dcube.getDimAttrNames().getAttrName());
Set<String> measures = new LinkedHashSet<String>();
- measures.addAll(cube.getMeasureNames().getMeasures());
+ measures.addAll(dcube.getMeasureNames().getMeasureName());
Map<String, String> properties = mapFromXProperties(cube.getProperties());
- double cubeWeight = cube.getWeight() == null ? 0d : cube.getWeight();
- return new DerivedCube(cube.getName(), measures, dims, properties, cubeWeight, parent);
+ return new DerivedCube(cube.getName(), measures, dims, properties, 0L, parent);
} else {
+ XBaseCube bcube = (XBaseCube)cube;
Set<CubeDimAttribute> dims = new LinkedHashSet<CubeDimAttribute>();
- for (XDimAttribute xd : cube.getDimAttributes().getDimAttributes()) {
- dims.add(hiveDimAttrFromXDimAttr(xd));
+ if (bcube.getDimAttributes() != null && !bcube.getDimAttributes().getDimAttribute().isEmpty()) {
+ for (XDimAttribute xd : bcube.getDimAttributes().getDimAttribute()) {
+ dims.add(hiveDimAttrFromXDimAttr(xd));
+ }
}
Set<CubeMeasure> measures = new LinkedHashSet<CubeMeasure>();
- for (XMeasure xm : cube.getMeasures().getMeasures()) {
+ for (XMeasure xm : bcube.getMeasures().getMeasure()) {
measures.add(hiveMeasureFromXMeasure(xm));
}
Set<ExprColumn> expressions = new LinkedHashSet<ExprColumn>();
- if (cube.getExpressions() != null) {
- for (XExprColumn xe : cube.getExpressions().getExpressions()) {
+ if (bcube.getExpressions() != null && !bcube.getExpressions().getExpression().isEmpty()) {
+ for (XExprColumn xe : bcube.getExpressions().getExpression()) {
expressions.add(hiveExprColumnFromXExprColumn(xe));
}
}
Set<JoinChain> joinchains = new LinkedHashSet<JoinChain>();
- if (cube.getJoinchains() != null) {
- for (XJoinChain xj : cube.getJoinchains().getChains()) {
+ if (bcube.getJoinChains() != null && !bcube.getJoinChains().getJoinChain().isEmpty()) {
+ for (XJoinChain xj : bcube.getJoinChains().getJoinChain()) {
joinchains.add(joinChainFromXJoinChain(xj));
}
}
Map<String, String> properties = mapFromXProperties(cube.getProperties());
- double cubeWeight = cube.getWeight() == null ? 0d : cube.getWeight();
- return new Cube(cube.getName(), measures, dims, expressions, joinchains, properties, cubeWeight);
+ return new Cube(cube.getName(), measures, dims, expressions, joinchains, properties, 0L);
}
}
@@ -106,49 +107,39 @@ public class JAXBUtils {
* @return {@link XCube}
*/
public static XCube xCubeFromHiveCube(CubeInterface c) {
-
- XCube xc = XCF.createXCube();
- xc.setName(c.getName());
- xc.setWeight(((AbstractCubeTable)c).weight());
- xc.setProperties(xPropertiesFromMap(((AbstractCubeTable)c).getProperties()));
-
+ XCube xc;
if (c.isDerivedCube()) {
- xc.setMeasureNames(XCF.createXMeasureNames());
- xc.getMeasureNames().getMeasures().addAll(c.getMeasureNames());
- xc.setDimAttrNames(XCF.createXDimAttrNames());
- xc.getDimAttrNames().getDimAttrNames().addAll(c.getDimAttributeNames());
- xc.setParent(((DerivedCube)c).getParent().getName());
- xc.setDerived(true);
+ XDerivedCube xdc = XCF.createXDerivedCube();
+ xdc.setMeasureNames(new XMeasureNames());
+ xdc.setDimAttrNames(new XDimAttrNames());
+ xc = xdc;
+ xdc.getMeasureNames().getMeasureName().addAll(c.getMeasureNames());
+ xdc.getDimAttrNames().getAttrName().addAll(c.getDimAttributeNames());
+ xdc.setParent(((DerivedCube)c).getParent().getName());
} else {
- XMeasures xms = XCF.createXMeasures();
- List<XMeasure> xmsList = xms.getMeasures();
+ XBaseCube xbc = XCF.createXBaseCube();
+ xbc.setMeasures(new XMeasures());
+ xbc.setDimAttributes(new XDimAttributes());
+ xbc.setExpressions(new XExpressions());
+ xbc.setJoinChains(new XJoinChains());
+ xc = xbc;
for (CubeMeasure cm : c.getMeasures()) {
- xmsList.add(xMeasureFromHiveMeasure(cm));
+ xbc.getMeasures().getMeasure().add(xMeasureFromHiveMeasure(cm));
}
- xc.setMeasures(xms);
- XExpressions xexprs = XCF.createXExpressions();
- List<XExprColumn> xexprList = xexprs.getExpressions();
for (ExprColumn ec : c.getExpressions()) {
- xexprList.add(xExprColumnFromHiveExprColumn(ec));
+ xbc.getExpressions().getExpression().add(xExprColumnFromHiveExprColumn(ec));
}
- xc.setExpressions(xexprs);
-
- XDimAttributes xdm = XCF.createXDimAttributes();
- List<XDimAttribute> xdmList = xdm.getDimAttributes();
for (CubeDimAttribute cd : c.getDimAttributes()) {
- xdmList.add(xDimAttrFromHiveDimAttr(cd, (Cube)c));
+ xbc.getDimAttributes().getDimAttribute().add(xDimAttrFromHiveDimAttr(cd, (Cube)c));
}
- xc.setDimAttributes(xdm);
-
- XJoinchains xjc = XCF.createXJoinchains();
- List<XJoinChain> chainSet = xjc.getChains();
for (JoinChain jc : c.getJoinChains()) {
- chainSet.add(xJoinChainFromJoinChain(jc));
+ xbc.getJoinChains().getJoinChain().add(XJoinChainFromJoinChain(jc));
}
- xjc.getChains().addAll(chainSet);
- xc.setJoinchains(xjc);
}
+ xc.setName(c.getName());
+ xc.setProperties(new XProperties());
+ xc.getProperties().getProperty().addAll(xPropertiesFromMap(((AbstractCubeTable)c).getProperties()));
return xc;
}
@@ -165,37 +156,41 @@ public class JAXBUtils {
CubeDimAttribute hiveDim;
- if (xd.getReferences() != null && xd.getReferences().getTableReferences() != null &&
- !xd.getReferences().getTableReferences().isEmpty()) {
+ if (xd.getRefSpec() != null && xd.getRefSpec().getTableReferences() != null &&
+ !xd.getRefSpec().getTableReferences().getTableReference().isEmpty()) {
- List<TableReference> dimRefs = new ArrayList<TableReference>(xd.getReferences().getTableReferences().size());
+ List<TableReference> dimRefs = new ArrayList<TableReference>(
+ xd.getRefSpec().getTableReferences().getTableReference().size());
- for (XTablereference xRef : xd.getReferences().getTableReferences()) {
- dimRefs.add(new TableReference(xRef.getDestTable(), xRef.getDestColumn()));
+ for (XTableReference xRef : xd.getRefSpec().getTableReferences().getTableReference()) {
+ dimRefs.add(new TableReference(xRef.getTable(), xRef.getColumn()));
}
- hiveDim = new ReferencedDimAtrribute(new FieldSchema(xd.getName(), xd.getType(), xd.getDescription()),
+ hiveDim = new ReferencedDimAtrribute(new FieldSchema(xd.getName(), xd.getType().name().toLowerCase(),
+ xd.getDescription()),
xd.getDisplayString(),
dimRefs,
startDate,
endDate,
- xd.getCost()
+ null
);
- } else if (xd.getChainRefColumn() != null) {
- hiveDim = new ReferencedDimAtrribute(new FieldSchema(xd.getName(), xd.getType(), xd.getDescription()),
+ } else if (xd.getRefSpec() != null && xd.getRefSpec().getChainRefColumn() != null) {
+ hiveDim = new ReferencedDimAtrribute(new FieldSchema(xd.getName(), xd.getType().name().toLowerCase(),
+ xd.getDescription()),
xd.getDisplayString(),
- xd.getChainRefColumn().getChainName(),
- xd.getChainRefColumn().getRefCol(),
+ xd.getRefSpec().getChainRefColumn().getChainName(),
+ xd.getRefSpec().getChainRefColumn().getRefCol(),
startDate,
endDate,
- xd.getCost()
+ null
);
} else {
- hiveDim = new BaseDimAttribute(new FieldSchema(xd.getName(), xd.getType(), xd.getDescription()),
+ hiveDim = new BaseDimAttribute(new FieldSchema(xd.getName(), xd.getType().name().toLowerCase(),
+ xd.getDescription()),
xd.getDisplayString(),
startDate,
endDate,
- xd.getCost()
+ null
);
}
@@ -238,9 +233,8 @@ public class JAXBUtils {
xm.setDisplayString(cm.getDisplayString());
xm.setDefaultAggr(cm.getAggregate());
xm.setFormatString(cm.getFormatString());
- xm.setType(cm.getType());
+ xm.setType(XMeasureType.valueOf(cm.getType().toUpperCase()));
xm.setUnit(cm.getUnit());
- xm.setCost(cm.getCost());
xm.setStartTime(getXMLGregorianCalendar(cm.getStartTime()));
xm.setEndTime(getXMLGregorianCalendar(cm.getEndTime()));
xm.setMin(cm.getMin());
@@ -258,7 +252,7 @@ public class JAXBUtils {
XExprColumn xe = XCF.createXExprColumn();
xe.setName(ec.getName());
- xe.setType(ec.getType());
+ xe.setType(XColumnType.valueOf(ec.getType().toUpperCase()));
xe.setDescription(ec.getDescription());
xe.setDisplayString(ec.getDisplayString());
xe.setExpr(ec.getExpr());
@@ -266,32 +260,32 @@ public class JAXBUtils {
}
/**
- * Create XDimension from hive ql cube dimension
+ * Create XDimAttribute from CubeDimAttribute
*/
public static XDimAttribute xDimAttrFromHiveDimAttr(CubeDimAttribute cd, AbstractBaseTable baseTable) {
XDimAttribute xd = XCF.createXDimAttribute();
xd.setName(cd.getName());
xd.setDescription(cd.getDescription());
xd.setDisplayString(cd.getDisplayString());
-
if (cd instanceof ReferencedDimAtrribute) {
ReferencedDimAtrribute rd = (ReferencedDimAtrribute) cd;
List<TableReference> dimRefs = rd.getReferences();
+ XDimAttribute.RefSpec refspec = XCF.createXDimAttributeRefSpec();
if (rd.getChainName() != null) {
XChainColumn xcc = new XChainColumn();
xcc.setChainName(rd.getChainName());
xcc.setRefCol(rd.getRefColumn());
xcc.setDestTable(baseTable.getChainByName(rd.getChainName()).getDestTable());
- xd.setChainRefColumn(xcc);
+ refspec.setChainRefColumn(xcc);
} else {
- xd.setReferences(xTabReferenceFromHiveTabReference(dimRefs));
+ refspec.setTableReferences(new XTableReferences());
+ refspec.getTableReferences().getTableReference().addAll(xTabReferencesFromHiveTabReferences(dimRefs));
}
- xd.setType(rd.getType());
- xd.setCost(rd.getCost());
+ xd.setRefSpec(refspec);
+ xd.setType(XColumnType.valueOf(rd.getType().toUpperCase()));
} else if (cd instanceof BaseDimAttribute) {
BaseDimAttribute bd = (BaseDimAttribute) cd;
- xd.setType(bd.getType());
- xd.setCost(bd.getCost());
+ xd.setType(XColumnType.valueOf(bd.getType().toUpperCase()));
}
return xd;
}
@@ -299,32 +293,47 @@ public class JAXBUtils {
/**
* Create XJoinChain from cube join chain
*/
- public static XJoinChain xJoinChainFromJoinChain(JoinChain jc) {
+ public static XJoinChain XJoinChainFromJoinChain(JoinChain jc) {
XJoinChain xjc = XCF.createXJoinChain();
xjc.setName(jc.getName());
xjc.setDescription(jc.getDescription());
xjc.setDisplayString(jc.getDisplayString());
xjc.setDestTable(jc.getDestTable());
+ xjc.setPaths(new XJoinPaths());
for (JoinChain.Path path : jc.getPaths()) {
- xjc.getPaths().add(xTabReferenceFromHiveTabReference(path.getReferences()));
+ xjc.getPaths().getPath().add(xJoinPathFromJoinPath(path));
}
return xjc;
}
- public static XTablereferences xTabReferenceFromHiveTabReference(List<TableReference> hiveRefs) {
- XTablereferences xrefs = XCF.createXTablereferences();
- List<XTablereference> xrefList = xrefs.getTableReferences();
+ public static XJoinPath xJoinPathFromJoinPath(JoinChain.Path path) {
+ XJoinPath xjp = XCF.createXJoinPath();
+ xjp.setEdges(new XJoinEdges());
+ for (JoinChain.Edge edge: path.getLinks()) {
+ XJoinEdge xje = XCF.createXJoinEdge();
+ xje.setFrom(xTabReferenceFromTabReference(edge.getFrom()));
+ xje.setTo(xTabReferenceFromTabReference(edge.getTo()));
+ xjp.getEdges().getEdge().add(xje);
+ }
+ return xjp;
+ }
+
+ public static List<XTableReference> xTabReferencesFromHiveTabReferences(List<TableReference> hiveRefs) {
+ List<XTableReference> xrefList = new ArrayList<XTableReference>();
for (TableReference hRef : hiveRefs) {
- XTablereference xref = XCF.createXTablereference();
- xref.setDestTable(hRef.getDestTable());
- xref.setDestColumn(hRef.getDestColumn());
- xrefList.add(xref);
+ xrefList.add(xTabReferenceFromTabReference(hRef));
}
- return xrefs;
+ return xrefList;
}
+ private static XTableReference xTabReferenceFromTabReference(TableReference ref) {
+ XTableReference xref = XCF.createXTableReference();
+ xref.setTable(ref.getDestTable());
+ xref.setColumn(ref.getDestColumn());
+ return xref;
+ }
/**
* Create hive ql CubeMeasure from JAXB counterpart
*
@@ -335,14 +344,15 @@ public class JAXBUtils {
public static CubeMeasure hiveMeasureFromXMeasure(XMeasure xm) {
Date startDate = xm.getStartTime() == null ? null : xm.getStartTime().toGregorianCalendar().getTime();
Date endDate = xm.getEndTime() == null ? null : xm.getEndTime().toGregorianCalendar().getTime();
- CubeMeasure cm = new ColumnMeasure(new FieldSchema(xm.getName(), xm.getType(), xm.getDescription()),
+ CubeMeasure cm = new ColumnMeasure(new FieldSchema(xm.getName(), xm.getType().name().toLowerCase(),
+ xm.getDescription()),
xm.getDisplayString(),
xm.getFormatString(),
xm.getDefaultAggr(),
xm.getUnit(),
startDate,
endDate,
- xm.getCost(),
+ null,
xm.getMin(),
xm.getMax()
);
@@ -358,12 +368,13 @@ public class JAXBUtils {
*/
public static JoinChain joinChainFromXJoinChain(XJoinChain xj) {
JoinChain jc = new JoinChain(xj.getName(), xj.getDisplayString(), xj.getDescription());
- for (int i = 0; i < xj.getPaths().size(); i++) {
- XTablereferences xchain = xj.getPaths().get(i);
- List<TableReference> chain = new ArrayList<TableReference>(xchain.getTableReferences().size());
+ for (int i = 0; i < xj.getPaths().getPath().size(); i++) {
+ XJoinPath xchain = xj.getPaths().getPath().get(i);
+ List<TableReference> chain = new ArrayList<TableReference>(xchain.getEdges().getEdge().size() * 2);
- for (XTablereference xRef : xchain.getTableReferences()) {
- chain.add(new TableReference(xRef.getDestTable(), xRef.getDestColumn()));
+ for (XJoinEdge xRef : xchain.getEdges().getEdge()) {
+ chain.add(new TableReference(xRef.getFrom().getTable(), xRef.getFrom().getColumn()));
+ chain.add(new TableReference(xRef.getTo().getTable(), xRef.getTo().getColumn()));
}
jc.addPath(chain);
}
@@ -371,7 +382,8 @@ public class JAXBUtils {
}
public static ExprColumn hiveExprColumnFromXExprColumn(XExprColumn xe) throws ParseException {
- ExprColumn ec = new ExprColumn(new FieldSchema(xe.getName(), xe.getType(), xe.getDescription()),
+ ExprColumn ec = new ExprColumn(new FieldSchema(xe.getName(), xe.getType().name().toLowerCase(),
+ xe.getDescription()),
xe.getDisplayString(),
xe.getExpr());
return ec;
@@ -386,9 +398,8 @@ public class JAXBUtils {
*/
public static Map<String, String> mapFromXProperties(XProperties xProperties) {
Map<String, String> properties = new HashMap<String, String>();
- if (xProperties != null && xProperties.getProperties() != null &&
- !xProperties.getProperties().isEmpty()) {
- for (XProperty xp : xProperties.getProperties()) {
+ if (xProperties != null && !xProperties.getProperty().isEmpty()) {
+ for (XProperty xp : xProperties.getProperty()) {
properties.put(xp.getName(), xp.getValue());
}
}
@@ -398,46 +409,42 @@ public class JAXBUtils {
/**
* Convert string map to XProperties
*/
- public static XProperties xPropertiesFromMap(Map<String, String> map) {
+ public static List<XProperty> xPropertiesFromMap(Map<String, String> map) {
+ List<XProperty> xpList = new ArrayList<XProperty>();
if (map != null && !map.isEmpty()) {
- XProperties xp = XCF.createXProperties();
- List<XProperty> xpList = xp.getProperties();
for (Map.Entry<String, String> e : map.entrySet()) {
XProperty property = XCF.createXProperty();
property.setName(e.getKey());
property.setValue(e.getValue());
xpList.add(property);
}
-
- return xp;
}
- return null;
+ return xpList;
}
- public static FieldSchema fieldSchemaFromColumn(Column c) {
+ public static FieldSchema fieldSchemaFromColumn(XColumn c) {
if (c == null) {
return null;
}
- return new FieldSchema(c.getName(), c.getType(), c.getComment());
+ return new FieldSchema(c.getName(), c.getType().name().toLowerCase(), c.getComment());
}
- public static Column columnFromFieldSchema(FieldSchema fs) {
+ public static XColumn columnFromFieldSchema(FieldSchema fs) {
if (fs == null) {
return null;
}
- Column c = XCF.createColumn();
+ XColumn c = XCF.createXColumn();
c.setName(fs.getName());
- c.setType(fs.getType());
+ c.setType(XColumnType.valueOf(fs.getType().toUpperCase()));
c.setComment(fs.getComment());
return c;
}
- public static ArrayList<FieldSchema> fieldSchemaListFromColumns(Columns columns) {
- if (columns != null && columns.getColumns() != null && !columns.getColumns().isEmpty()) {
- ArrayList<FieldSchema> fsList = new ArrayList<FieldSchema>(columns.getColumns().size());
- for (Column c : columns.getColumns()) {
- LOG.debug("##Column "+ c.getName() + "-" + c.getType());
+ public static ArrayList<FieldSchema> fieldSchemaListFromColumns(XColumns columns) {
+ if (columns != null && !columns.getColumn().isEmpty()) {
+ ArrayList<FieldSchema> fsList = new ArrayList<FieldSchema>(columns.getColumn().size());
+ for (XColumn c : columns.getColumn()) {
fsList.add(fieldSchemaFromColumn(c));
}
return fsList;
@@ -445,46 +452,47 @@ public class JAXBUtils {
return null;
}
- public static Columns columnsFromFieldSchemaList(List<FieldSchema> fslist) {
+ public static List<XColumn> columnsFromFieldSchemaList(List<FieldSchema> fslist) {
if (fslist == null || fslist.isEmpty()) {
return null;
}
- Columns cols = XCF.createColumns();
+ List<XColumn> cols = new ArrayList<XColumn>();
for (FieldSchema fs : fslist) {
- cols.getColumns().add(columnFromFieldSchema(fs));
+ cols.add(columnFromFieldSchema(fs));
}
return cols;
}
- public static Map<String, Set<UpdatePeriod>> getFactUpdatePeriodsFromUpdatePeriods(UpdatePeriods periods) {
- if (periods != null && periods.getUpdatePeriodElement() != null && !periods.getUpdatePeriodElement().isEmpty()) {
- Map<String, Set<UpdatePeriod>> map = new LinkedHashMap<String, Set<UpdatePeriod>>();
+ public static Map<String, Set<UpdatePeriod>> getFactUpdatePeriodsFromStorageTables(
+ XStorageTables storageTables) {
+ if (storageTables != null && !storageTables.getStorageTable().isEmpty()) {
+ Map<String, Set<UpdatePeriod>> factUpdatePeriods = new LinkedHashMap<String, Set<UpdatePeriod>>();
- for (UpdatePeriodElement upd : periods.getUpdatePeriodElement()) {
+ for (XStorageTableElement ste : storageTables.getStorageTable()) {
Set<UpdatePeriod> updatePeriods = new TreeSet<UpdatePeriod>();
- for (String updStr : upd.getUpdatePeriods()) {
- updatePeriods.add(UpdatePeriod.valueOf(updStr.toUpperCase()));
+ for (XUpdatePeriod upd : ste.getUpdatePeriods().getUpdatePeriod()) {
+ updatePeriods.add(UpdatePeriod.valueOf(upd.name()));
}
- map.put(upd.getStorageName(), updatePeriods);
+ factUpdatePeriods.put(ste.getStorageName(), updatePeriods);
}
- return map;
+ return factUpdatePeriods;
}
return null;
}
- public static Map<String, UpdatePeriod> dumpPeriodsFromUpdatePeriods(UpdatePeriods periods) {
- if (periods != null && periods.getUpdatePeriodElement() != null && !periods.getUpdatePeriodElement().isEmpty()) {
- Map<String, UpdatePeriod> map = new LinkedHashMap<String, UpdatePeriod>();
+ public static Map<String, UpdatePeriod> dumpPeriodsFromStorageTables(XStorageTables storageTables) {
+ if (storageTables != null && !storageTables.getStorageTable().isEmpty()) {
+ Map<String, UpdatePeriod> dumpPeriods = new LinkedHashMap<String, UpdatePeriod>();
- for (UpdatePeriodElement upd : periods.getUpdatePeriodElement()) {
+ for (XStorageTableElement ste : storageTables.getStorageTable()) {
UpdatePeriod dumpPeriod = null;
- if (upd.getUpdatePeriods().size() > 0) {
- dumpPeriod = UpdatePeriod.valueOf(upd.getUpdatePeriods().get(0).toUpperCase());
+ if (ste.getUpdatePeriods() != null && !ste.getUpdatePeriods().getUpdatePeriod().isEmpty()) {
+ dumpPeriod = UpdatePeriod.valueOf(ste.getUpdatePeriods().getUpdatePeriod().get(0).name());
}
- map.put(upd.getStorageName(), dumpPeriod);
+ dumpPeriods.put(ste.getStorageName(), dumpPeriod);
}
- return map;
+ return dumpPeriods;
}
return null;
}
@@ -514,57 +522,42 @@ public class JAXBUtils {
XStorage xstorage = null;
xstorage = XCF.createXStorage();
+ xstorage.setProperties(new XProperties());
xstorage.setName(storage.getName());
xstorage.setClassname(storage.getClass().getCanonicalName());
- xstorage.setProperties(xPropertiesFromMap(storage.getProperties()));
+ xstorage.getProperties().getProperty().addAll(xPropertiesFromMap(storage.getProperties()));
return xstorage;
}
- public static DimensionTable dimTableFromCubeDimTable(CubeDimensionTable cubeDimTable) {
+ public static XDimensionTable dimTableFromCubeDimTable(CubeDimensionTable cubeDimTable) {
if (cubeDimTable == null) {
return null;
}
- DimensionTable dimTab = XCF.createDimensionTable();
- dimTab.setDimName(cubeDimTable.getDimName());
+ XDimensionTable dimTab = XCF.createXDimensionTable();
+ dimTab.setDimensionName(cubeDimTable.getDimName());
dimTab.setTableName(cubeDimTable.getName());
dimTab.setWeight(cubeDimTable.weight());
-
- Columns cols = XCF.createColumns();
+ dimTab.setColumns(new XColumns());
+ dimTab.setProperties(new XProperties());
+ dimTab.setStorageTables(new XStorageTables());
for (FieldSchema column : cubeDimTable.getColumns()) {
- cols.getColumns().add(columnFromFieldSchema(column));
- }
- dimTab.setColumns(cols);
-
- dimTab.setProperties(xPropertiesFromMap(cubeDimTable.getProperties()));
-
- Map<String, UpdatePeriod> storageToUpdatePeriod = cubeDimTable.getSnapshotDumpPeriods();
- if (storageToUpdatePeriod != null && !storageToUpdatePeriod.isEmpty()) {
- UpdatePeriods periods = XCF.createUpdatePeriods();
-
- for (Entry<String, UpdatePeriod> entry : storageToUpdatePeriod.entrySet()) {
- UpdatePeriodElement e = XCF.createUpdatePeriodElement();
- e.setStorageName(entry.getKey());
- if (entry.getValue() != null) {
- e.getUpdatePeriods().add(entry.getValue().toString());
- }
- periods.getUpdatePeriodElement().add(e);
- }
- dimTab.setStorageDumpPeriods(periods);
+ dimTab.getColumns().getColumn().add(columnFromFieldSchema(column));
}
+ dimTab.getProperties().getProperty().addAll(xPropertiesFromMap(cubeDimTable.getProperties()));
return dimTab;
}
- public static List<? extends XTablereference> dimRefListFromTabRefList(
+ public static List<? extends XTableReference> dimRefListFromTabRefList(
List<TableReference> tabRefs) {
if (tabRefs != null && !tabRefs.isEmpty()) {
- List<XTablereference> xTabRefs = new ArrayList<XTablereference>(tabRefs.size());
+ List<XTableReference> xTabRefs = new ArrayList<XTableReference>(tabRefs.size());
for (TableReference ref : tabRefs) {
- XTablereference xRef = XCF.createXTablereference();
- xRef.setDestColumn(ref.getDestColumn());
- xRef.setDestTable(ref.getDestTable());
+ XTableReference xRef = XCF.createXTableReference();
+ xRef.setColumn(ref.getDestColumn());
+ xRef.setTable(ref.getDestTable());
xTabRefs.add(xRef);
}
return xTabRefs;
@@ -573,22 +566,23 @@ public class JAXBUtils {
return null;
}
- public static CubeDimensionTable cubeDimTableFromDimTable(DimensionTable dimensionTable) {
+ public static CubeDimensionTable cubeDimTableFromDimTable(XDimensionTable dimensionTable) {
- CubeDimensionTable cdim = new CubeDimensionTable(dimensionTable.getDimName(),
+ CubeDimensionTable cdim = new CubeDimensionTable(dimensionTable.getDimensionName(),
dimensionTable.getTableName(),
fieldSchemaListFromColumns(dimensionTable.getColumns()),
dimensionTable.getWeight(),
- dumpPeriodsFromUpdatePeriods(dimensionTable.getStorageDumpPeriods()),
+ dumpPeriodsFromStorageTables(dimensionTable.getStorageTables()),
mapFromXProperties(dimensionTable.getProperties()));
return cdim;
}
- public static CubeFactTable cubeFactFromFactTable(FactTable fact) {
+ public static CubeFactTable cubeFactFromFactTable(XFactTable fact) {
List<FieldSchema> columns = fieldSchemaListFromColumns(fact.getColumns());
- Map<String, Set<UpdatePeriod>> storageUpdatePeriods = getFactUpdatePeriodsFromUpdatePeriods(fact.getStorageUpdatePeriods());
+ Map<String, Set<UpdatePeriod>> storageUpdatePeriods = getFactUpdatePeriodsFromStorageTables(
+ fact.getStorageTables());
return new CubeFactTable(fact.getCubeName(),
fact.getName(),
@@ -598,26 +592,17 @@ public class JAXBUtils {
mapFromXProperties(fact.getProperties()));
}
- public static FactTable factTableFromCubeFactTable(CubeFactTable cFact) {
- FactTable fact = XCF.createFactTable();
+ public static XFactTable factTableFromCubeFactTable(CubeFactTable cFact) {
+ XFactTable fact = XCF.createXFactTable();
fact.setName(cFact.getName());
- fact.setProperties(xPropertiesFromMap(cFact.getProperties()));
- fact.setColumns(columnsFromFieldSchemaList(cFact.getColumns()));
+ fact.setColumns(new XColumns());
+ fact.setProperties(new XProperties());
+ fact.setStorageTables(new XStorageTables());
+
+ fact.getProperties().getProperty().addAll(xPropertiesFromMap(cFact.getProperties()));
+ fact.getColumns().getColumn().addAll(columnsFromFieldSchemaList(cFact.getColumns()));
fact.setWeight(cFact.weight());
fact.setCubeName(cFact.getCubeName());
-
- if (cFact.getUpdatePeriods() != null && !cFact.getUpdatePeriods().isEmpty()) {
- UpdatePeriods periods = XCF.createUpdatePeriods();
- for (Map.Entry<String, Set<UpdatePeriod>> e : cFact.getUpdatePeriods().entrySet()) {
- UpdatePeriodElement uel = XCF.createUpdatePeriodElement();
- uel.setStorageName(e.getKey());
- for (UpdatePeriod p : e.getValue()) {
- uel.getUpdatePeriods().add(p.toString());
- }
- periods.getUpdatePeriodElement().add(uel);
- }
- fact.setStorageUpdatePeriods(periods);
- }
return fact;
}
@@ -649,13 +634,17 @@ public class JAXBUtils {
public static XStorageTableElement getXStorageTableFromHiveTable(Table tbl) {
XStorageTableElement tblElement = new XStorageTableElement();
+ tblElement.setUpdatePeriods(new XUpdatePeriods());
tblElement.setTableDesc(getStorageTableDescFromHiveTable(tbl));
return tblElement;
}
public static XStorageTableDesc getStorageTableDescFromHiveTable(Table tbl) {
XStorageTableDesc tblDesc = new XStorageTableDesc();
- tblDesc.setPartCols(columnsFromFieldSchemaList(tbl.getPartCols()));
+ tblDesc.setPartCols(new XColumns());
+ tblDesc.setTableParameters(new XProperties());
+ tblDesc.setSerdeParameters(new XProperties());
+ tblDesc.getPartCols().getColumn().addAll(columnsFromFieldSchemaList(tbl.getPartCols()));
String timePartCols = tbl.getParameters().get(MetastoreConstants.TIME_PART_COLUMNS);
if (timePartCols != null) {
tblDesc.getTimePartCols().addAll(Arrays.asList(org.apache.commons.lang.StringUtils.split(timePartCols, ",")));
@@ -674,19 +663,20 @@ public class JAXBUtils {
XSkewedInfo xskewinfo = new XSkewedInfo();
xskewinfo.getColNames().addAll(tbl.getSkewedColNames());
for (List<String> value : tbl.getSkewedColValues()) {
- XStringList slist = new XStringList();
- slist.getElements().addAll(value);
- xskewinfo.getColValues().add(slist);
+ XSkewColList colVallist = new XSkewColList();
+ colVallist.getElements().addAll(value);
+ xskewinfo.getColValues().add(colVallist);
XSkewedValueLocation valueLocation = new XSkewedValueLocation();
if (tbl.getSkewedColValueLocationMaps().get(value) != null) {
- valueLocation.setValue(slist);
+ valueLocation.setValue(colVallist);
valueLocation.setLocation(tbl.getSkewedColValueLocationMaps().get(value));
xskewinfo.getValueLocationMap().add(valueLocation);
}
}
- tblDesc.setTableParameters(xPropertiesFromMap(tbl.getParameters()));
- tblDesc.setSerdeParameters(xPropertiesFromMap(tbl.getTTable().getSd().getSerdeInfo().getParameters()));
+ tblDesc.getTableParameters().getProperty().addAll(xPropertiesFromMap(tbl.getParameters()));
+ tblDesc.getSerdeParameters().getProperty().addAll(xPropertiesFromMap(
+ tbl.getTTable().getSd().getSerdeInfo().getParameters()));
tblDesc.setExternal(tbl.getTableType().equals(TableType.EXTERNAL_TABLE));
tblDesc.setCompressed(tbl.getTTable().getSd().isCompressed());
tblDesc.setTableLocation(tbl.getDataLocation().toString());
@@ -705,8 +695,10 @@ public class JAXBUtils {
public static Map<String, StorageTableDesc> storageTableMapFromXStorageTables(XStorageTables storageTables) {
Map<String, StorageTableDesc> storageTableMap = new HashMap<String, StorageTableDesc>();
- for (XStorageTableElement sTbl : storageTables.getStorageTables()) {
- storageTableMap.put(sTbl.getStorageName(), storageTableDescFromXStorageTableElement(sTbl));
+ if (storageTables != null && !storageTables.getStorageTable().isEmpty()) {
+ for (XStorageTableElement sTbl : storageTables.getStorageTable()) {
+ storageTableMap.put(sTbl.getStorageName(), storageTableDescFromXStorageTableElement(sTbl));
+ }
}
return storageTableMap;
}
@@ -714,7 +706,7 @@ public class JAXBUtils {
public static Map<String, Date> timePartSpecfromXTimePartSpec(
XTimePartSpec xtimePartSpec) {
Map<String, Date> timePartSpec = new HashMap<String, Date>();
- if (xtimePartSpec != null) {
+ if (xtimePartSpec != null && !xtimePartSpec.getPartSpecElement().isEmpty()) {
for (XTimePartSpecElement xtimePart : xtimePartSpec.getPartSpecElement()) {
timePartSpec.put(xtimePart.getKey(), getDateFromXML(xtimePart.getValue()));
}
@@ -725,7 +717,7 @@ public class JAXBUtils {
public static Map<String, String> nonTimePartSpecfromXNonTimePartSpec(
XPartSpec xnonTimePartSpec) {
Map<String, String> nonTimePartSpec = new HashMap<String, String>();
- if (xnonTimePartSpec != null) {
+ if (xnonTimePartSpec != null && !xnonTimePartSpec.getPartSpecElement().isEmpty()) {
for (XPartSpecElement xPart : xnonTimePartSpec.getPartSpecElement()) {
nonTimePartSpec.put(xPart.getKey(), xPart.getValue());
}
@@ -735,35 +727,35 @@ public class JAXBUtils {
public static XPartition xpartitionFromPartition(Partition p) throws HiveException {
XPartition xp = new XPartition();
+ xp.setFullPartitionSpec(new XPartSpec());
+ xp.setPartitionParameters(new XProperties());
+ xp.setSerdeParameters(new XProperties());
xp.setName(p.getCompleteName());
xp.setLocation(p.getLocation());
xp.setInputFormat(p.getInputFormatClass().getCanonicalName());
xp.setOutputFormat(p.getOutputFormatClass().getCanonicalName());
- xp.setPartitionParameters(xPropertiesFromMap(p.getParameters()));
- String timePartColsStr = p.getTable().getTTable().getParameters().get(MetastoreConstants.TIME_PART_COLUMNS);
+ xp.getPartitionParameters().getProperty().addAll(xPropertiesFromMap(p.getParameters()));
String upParam = p.getParameters().get(MetastoreConstants.PARTITION_UPDATE_PERIOD);
- xp.setUpdatePeriod(upParam);
- UpdatePeriod period = UpdatePeriod.valueOf(upParam);
- XPartSpec xps = new XPartSpec();
+ xp.setUpdatePeriod(XUpdatePeriod.valueOf(upParam));
for (Map.Entry<String, String> entry : p.getSpec().entrySet()) {
XPartSpecElement e = new XPartSpecElement();
e.setKey(entry.getKey());
e.setValue(entry.getValue());
- xps.getPartSpecElement().add(e);
+ xp.getFullPartitionSpec().getPartSpecElement().add(e);
}
- xp.setFullPartitionSpec(xps);
xp.setSerdeClassname(p.getTPartition().getSd().getSerdeInfo().getSerializationLib());
- xp.setSerdeParameters(xPropertiesFromMap(p.getTPartition().getSd().getSerdeInfo().getParameters()));
+ xp.getSerdeParameters().getProperty().addAll(xPropertiesFromMap(
+ p.getTPartition().getSd().getSerdeInfo().getParameters()));
return xp;
}
public static StoragePartitionDesc storagePartSpecFromXPartition(
XPartition xpart) {
StoragePartitionDesc partDesc = new StoragePartitionDesc(
- xpart.getCubeTableName(),
+ xpart.getFactOrDimensionTableName(),
timePartSpecfromXTimePartSpec(xpart.getTimePartitionSpec()),
nonTimePartSpecfromXNonTimePartSpec(xpart.getNonTimePartitionSpec()),
- UpdatePeriod.valueOf(xpart.getUpdatePeriod().toUpperCase()));
+ UpdatePeriod.valueOf(xpart.getUpdatePeriod().name()));
partDesc.setPartParams(mapFromXProperties(xpart.getPartitionParameters()));
partDesc.setSerdeParams(mapFromXProperties(xpart.getSerdeParameters()));
partDesc.setLocation(xpart.getLocation());
@@ -775,69 +767,63 @@ public class JAXBUtils {
public static Dimension dimensionFromXDimension(XDimension dimension) throws ParseException {
Set<CubeDimAttribute> dims = new LinkedHashSet<CubeDimAttribute>();
- for (XDimAttribute xd : dimension.getAttributes().getDimAttributes()) {
+ for (XDimAttribute xd : dimension.getAttributes().getDimAttribute()) {
dims.add(hiveDimAttrFromXDimAttr(xd));
}
Set<ExprColumn> expressions = new LinkedHashSet<ExprColumn>();
- if (dimension.getExpressions() != null) {
- for (XExprColumn xe : dimension.getExpressions().getExpressions()) {
+ if (dimension.getExpressions() != null && !dimension.getExpressions().getExpression().isEmpty()) {
+ for (XExprColumn xe : dimension.getExpressions().getExpression()) {
expressions.add(hiveExprColumnFromXExprColumn(xe));
}
}
Set<JoinChain> joinchains = new LinkedHashSet<JoinChain>();
- if (dimension.getJoinchains() != null) {
- for (XJoinChain xj : dimension.getJoinchains().getChains()) {
+ if (dimension.getJoinChains() != null && !dimension.getJoinChains().getJoinChain().isEmpty()) {
+ for (XJoinChain xj : dimension.getJoinChains().getJoinChain()) {
joinchains.add(joinChainFromXJoinChain(xj));
}
}
Map<String, String> properties = mapFromXProperties(dimension.getProperties());
- double dimWeight = dimension.getWeight() == null ? 0d : dimension.getWeight();
- return new Dimension(dimension.getName(), dims, expressions, joinchains, properties, dimWeight);
+ return new Dimension(dimension.getName(), dims, expressions, joinchains, properties, 0L);
}
public static XDimension xdimensionFromDimension(Dimension dimension) {
XDimension xd = XCF.createXDimension();
xd.setName(dimension.getName());
- xd.setWeight(((AbstractCubeTable)dimension).weight());
- xd.setProperties(xPropertiesFromMap(((AbstractCubeTable)dimension).getProperties()));
- XDimAttributes xdm = XCF.createXDimAttributes();
- List<XDimAttribute> xdmList = xdm.getDimAttributes();
+ xd.setAttributes(new XDimAttributes());
+ xd.setExpressions(new XExpressions());
+ xd.setJoinChains(new XJoinChains());
+ xd.setProperties(new XProperties());
+
+ xd.getProperties().getProperty().addAll(xPropertiesFromMap(((AbstractCubeTable)dimension).getProperties()));
for (CubeDimAttribute cd : dimension.getAttributes()) {
- xdmList.add(xDimAttrFromHiveDimAttr(cd, dimension));
+ xd.getAttributes().getDimAttribute().add(xDimAttrFromHiveDimAttr(cd, dimension));
}
- xd.setAttributes(xdm);
- XExpressions xexprs = XCF.createXExpressions();
- List<XExprColumn> xexprList = xexprs.getExpressions();
for (ExprColumn ec : dimension.getExpressions()) {
- xexprList.add(xExprColumnFromHiveExprColumn(ec));
+ xd.getExpressions().getExpression().add(xExprColumnFromHiveExprColumn(ec));
}
- xd.setExpressions(xexprs);
- XJoinchains xjc = XCF.createXJoinchains();
- List<XJoinChain> chainSet = xjc.getChains();
for (JoinChain jc : dimension.getJoinChains()) {
- chainSet.add(xJoinChainFromJoinChain(jc));
+ xd.getJoinChains().getJoinChain().add(XJoinChainFromJoinChain(jc));
}
- xjc.getChains().addAll(chainSet);
- xd.setJoinchains(xjc);
return xd;
}
- public static NativeTable nativeTableFromMetaTable(Table table) {
- NativeTable xtable = XCF.createNativeTable();
+ public static XNativeTable nativeTableFromMetaTable(Table table) {
+ XNativeTable xtable = XCF.createXNativeTable();
+ xtable.setColumns(new XColumns());
xtable.setName(table.getTableName());
xtable.setDbname(table.getDbName());
xtable.setOwner(table.getOwner());
xtable.setCreatetime(table.getTTable().getCreateTime());
xtable.setLastAccessTime(table.getTTable().getLastAccessTime());
- xtable.setColumns(columnsFromFieldSchemaList(table.getCols()));
+ xtable.getColumns().getColumn().addAll(columnsFromFieldSchemaList(table.getCols()));
xtable.setStorageDescriptor(getStorageTableDescFromHiveTable(table));
- xtable.setType(table.getTableType().name());
+ xtable.setTableType(table.getTableType().name());
return xtable;
}
}