http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeDesc.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeDesc.java b/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeDesc.java deleted file mode 100644 index 41d75c2..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeDesc.java +++ /dev/null @@ -1,831 +0,0 @@ -/* - * 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.kylin.cube.model.v1; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.net.util.Base64; -import org.apache.kylin.common.KylinConfig; -import org.apache.kylin.common.persistence.ResourceStore; -import org.apache.kylin.common.persistence.RootPersistentEntity; -import org.apache.kylin.common.util.Array; -import org.apache.kylin.common.util.JsonUtil; -import org.apache.kylin.cube.model.HBaseColumnDesc; -import org.apache.kylin.cube.model.HBaseColumnFamilyDesc; -import org.apache.kylin.cube.model.HBaseMappingDesc; -import org.apache.kylin.cube.model.HierarchyDesc; -import org.apache.kylin.cube.model.RowKeyDesc; -import org.apache.kylin.metadata.MetadataConstants; -import org.apache.kylin.metadata.MetadataManager; -import org.apache.kylin.metadata.model.ColumnDesc; -import org.apache.kylin.metadata.model.FunctionDesc; -import org.apache.kylin.metadata.model.JoinDesc; -import org.apache.kylin.metadata.model.MeasureDesc; -import org.apache.kylin.metadata.model.ParameterDesc; -import org.apache.kylin.metadata.model.TableDesc; -import org.apache.kylin.metadata.model.TblColRef; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -/** - * Created with IntelliJ IDEA. User: lukhan Date: 9/24/13 Time: 10:40 AM To - * change this template use File | Settings | File Templates. - */ -@JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) -public class CubeDesc extends RootPersistentEntity { - - public static enum CubeCapacity { - SMALL, MEDIUM, LARGE; - } - - public static enum DeriveType { - LOOKUP, PK_FK - } - - public static class DeriveInfo { - public DeriveType type; - public DimensionDesc dimension; - public TblColRef[] columns; - public boolean isOneToOne; // only used when ref from derived to host - - DeriveInfo(DeriveType type, DimensionDesc dimension, TblColRef[] columns, boolean isOneToOne) { - this.type = type; - this.dimension = dimension; - this.columns = columns; - this.isOneToOne = isOneToOne; - } - - @Override - public String toString() { - return "DeriveInfo [type=" + type + ", dimension=" + dimension + ", columns=" + Arrays.toString(columns) + ", isOneToOne=" + isOneToOne + "]"; - } - - } - - private KylinConfig config; - - @JsonProperty("name") - private String name; - @JsonProperty("description") - private String description; - @JsonProperty("fact_table") - private String factTable; - @JsonProperty("null_string") - private String[] nullStrings; - @JsonProperty("filter_condition") - private String filterCondition; - @JsonProperty("cube_partition_desc") - CubePartitionDesc cubePartitionDesc; - @JsonProperty("dimensions") - private List<DimensionDesc> dimensions; - @JsonProperty("measures") - private List<MeasureDesc> measures; - @JsonProperty("rowkey") - private RowKeyDesc rowkey; - @JsonProperty("hbase_mapping") - private HBaseMappingDesc hbaseMapping; - @JsonProperty("signature") - private String signature; - @JsonProperty("capacity") - private CubeCapacity capacity = CubeCapacity.MEDIUM; - @JsonProperty("notify_list") - private List<String> notifyList; - - private Map<String, Map<String, TblColRef>> columnMap = new HashMap<String, Map<String, TblColRef>>(); - private LinkedHashSet<TblColRef> allColumns = new LinkedHashSet<TblColRef>(); - private LinkedHashSet<TblColRef> dimensionColumns = new LinkedHashSet<TblColRef>(); - private Map<TblColRef, DeriveInfo> derivedToHostMap = Maps.newHashMap(); - private Map<Array<TblColRef>, List<DeriveInfo>> hostToDerivedMap = Maps.newHashMap(); - - /** - * Error messages during resolving json metadata - */ - private List<String> errors = new ArrayList<String>(); - - /** - * @return all columns this cube can support, including derived - */ - public Set<TblColRef> listAllColumns() { - return allColumns; - } - - /** - * @return dimension columns including derived, BUT NOT measures - */ - public Set<TblColRef> listDimensionColumnsIncludingDerived() { - return dimensionColumns; - } - - /** - * @return dimension columns excluding derived and measures - */ - public List<TblColRef> listDimensionColumnsExcludingDerived() { - List<TblColRef> result = new ArrayList<TblColRef>(); - for (TblColRef col : dimensionColumns) { - if (isDerived(col) == false) - result.add(col); - } - return result; - } - - /** - * Find FunctionDesc by Full Expression. - * - * @return - */ - public FunctionDesc findFunctionOnCube(FunctionDesc manualFunc) { - for (MeasureDesc m : measures) { - if (m.getFunction().equals(manualFunc)) - return m.getFunction(); - } - return null; - } - - public TblColRef findColumnRef(String table, String column) { - Map<String, TblColRef> cols = columnMap.get(table); - if (cols == null) - return null; - else - return cols.get(column); - } - - public DimensionDesc findDimensionByColumn(TblColRef col) { - for (DimensionDesc dim : dimensions) { - if (ArrayUtils.contains(dim.getColumnRefs(), col)) - return dim; - } - return null; - } - - public DimensionDesc findDimensionByTable(String lookupTableName) { - lookupTableName = lookupTableName.toUpperCase(); - for (DimensionDesc dim : dimensions) - if (dim.getTable() != null && dim.getTable().equals(lookupTableName)) - return dim; - return null; - } - - public DimensionDesc findDimensionByName(String dimName) { - dimName = dimName.toUpperCase(); - for (DimensionDesc dim : dimensions) { - if (dimName.equals(dim.getName())) - return dim; - } - return null; - } - - public TblColRef findPKByFK(TblColRef fk) { - assert isFactTable(fk.getTable()); - - TblColRef candidate = null; - - for (DimensionDesc dim : dimensions) { - JoinDesc join = dim.getJoin(); - if (join == null) - continue; - - int find = ArrayUtils.indexOf(join.getForeignKeyColumns(), fk); - if (find >= 0) { - candidate = join.getPrimaryKeyColumns()[find]; - if (join.getForeignKeyColumns().length == 1) { // is single - // column join? - break; - } - } - } - return candidate; - } - - /** - * Get all functions from each measure. - * - * @return - */ - public List<FunctionDesc> listAllFunctions() { - List<FunctionDesc> functions = new ArrayList<FunctionDesc>(); - for (MeasureDesc m : measures) { - functions.add(m.getFunction()); - } - return functions; - } - - public List<TableDesc> listTables() { - MetadataManager metaMgr = MetadataManager.getInstance(config); - HashSet<String> tableNames = new HashSet<String>(); - List<TableDesc> result = new ArrayList<TableDesc>(); - - tableNames.add(factTable.toUpperCase()); - for (DimensionDesc dim : dimensions) { - String table = dim.getTable(); - if (table != null) - tableNames.add(table.toUpperCase()); - } - - for (String tableName : tableNames) { - result.add(metaMgr.getTableDesc(tableName)); - } - - return result; - } - - public boolean isFactTable(String factTable) { - return this.factTable.equalsIgnoreCase(factTable); - } - - public boolean isDerived(TblColRef col) { - return derivedToHostMap.containsKey(col); - } - - public DeriveInfo getHostInfo(TblColRef derived) { - return derivedToHostMap.get(derived); - } - - public Map<Array<TblColRef>, List<DeriveInfo>> getHostToDerivedInfo(List<TblColRef> rowCols, Collection<TblColRef> wantedCols) { - Map<Array<TblColRef>, List<DeriveInfo>> result = new HashMap<Array<TblColRef>, List<DeriveInfo>>(); - for (Entry<Array<TblColRef>, List<DeriveInfo>> entry : hostToDerivedMap.entrySet()) { - Array<TblColRef> hostCols = entry.getKey(); - boolean hostOnRow = rowCols.containsAll(Arrays.asList(hostCols.data)); - if (!hostOnRow) - continue; - - List<DeriveInfo> wantedInfo = new ArrayList<DeriveInfo>(); - for (DeriveInfo info : entry.getValue()) { - if (wantedCols == null || Collections.disjoint(wantedCols, Arrays.asList(info.columns)) == false) // has - // any - // wanted - // columns? - wantedInfo.add(info); - } - - if (wantedInfo.size() > 0) - result.put(hostCols, wantedInfo); - } - return result; - } - - public String getResourcePath() { - return getCubeDescResourcePath(name); - } - - public static String getCubeDescResourcePath(String descName) { - return ResourceStore.CUBE_DESC_RESOURCE_ROOT + "/" + descName + MetadataConstants.FILE_SURFIX; - } - - // ============================================================================ - - public HBaseMappingDesc getHBaseMapping() { - return hbaseMapping; - } - - public void setHBaseMapping(HBaseMappingDesc hbaseMapping) { - this.hbaseMapping = hbaseMapping; - } - - public KylinConfig getConfig() { - return config; - } - - public void setConfig(KylinConfig config) { - this.config = config; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getFactTable() { - return factTable; - } - - public void setFactTable(String factTable) { - this.factTable = factTable; - } - - public String[] getNullStrings() { - return nullStrings; - } - - public String getFilterCondition() { - return filterCondition; - } - - public void setFilterCondition(String filterCondition) { - this.filterCondition = filterCondition; - } - - public CubePartitionDesc getCubePartitionDesc() { - return cubePartitionDesc; - } - - public void setCubePartitionDesc(CubePartitionDesc cubePartitionDesc) { - this.cubePartitionDesc = cubePartitionDesc; - } - - public List<DimensionDesc> getDimensions() { - return dimensions; - } - - public void setDimensions(List<DimensionDesc> dimensions) { - this.dimensions = dimensions; - } - - public List<MeasureDesc> getMeasures() { - return measures; - } - - public void setMeasures(List<MeasureDesc> measures) { - this.measures = measures; - } - - public RowKeyDesc getRowkey() { - return rowkey; - } - - public void setRowkey(RowKeyDesc rowkey) { - this.rowkey = rowkey; - } - - public String getSignature() { - return signature; - } - - public void setSignature(String signature) { - this.signature = signature; - } - - public CubeCapacity getCapacity() { - return capacity; - } - - public void setCapacity(CubeCapacity capacity) { - this.capacity = capacity; - } - - public List<String> getNotifyList() { - return notifyList; - } - - public void setNotifyList(List<String> notifyList) { - this.notifyList = notifyList; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - CubeDesc cubeDesc = (CubeDesc) o; - - if (!name.equals(cubeDesc.name)) - return false; - if (!factTable.equals(cubeDesc.factTable)) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = 0; - result = 31 * result + name.hashCode(); - result = 31 * result + factTable.hashCode(); - return result; - } - - @Override - public String toString() { - return "CubeDesc [name=" + name + ", factTable=" + factTable + ", cubePartitionDesc=" + cubePartitionDesc + ", dimensions=" + dimensions + ", measures=" + measures + ", rowkey=" + rowkey + ", hbaseMapping=" + hbaseMapping + "]"; - } - - public String calculateSignature() { - MessageDigest md = null; - try { - md = MessageDigest.getInstance("MD5"); - StringBuilder sigString = new StringBuilder(); - sigString.append(this.name).append("|").append(this.factTable).append("|").append(JsonUtil.writeValueAsString(this.cubePartitionDesc)).append("|").append(JsonUtil.writeValueAsString(this.dimensions)).append("|").append(JsonUtil.writeValueAsString(this.measures)).append("|").append(JsonUtil.writeValueAsString(this.rowkey)).append("|").append(JsonUtil.writeValueAsString(this.hbaseMapping)); - - byte[] signature = md.digest(sigString.toString().getBytes()); - return new String(Base64.encodeBase64(signature)); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("Failed to calculate signature"); - } catch (JsonProcessingException e) { - throw new RuntimeException("Failed to calculate signature"); - } - } - - public Map<String, TblColRef> buildColumnNameAbbreviation() { - Map<String, TblColRef> r = new HashMap<String, TblColRef>(); - for (TblColRef col : listDimensionColumnsExcludingDerived()) { - r.put(col.getName(), col); - } - return r; - } - - public void init(KylinConfig config, Map<String, TableDesc> tables) { - this.errors.clear(); - this.config = config; - - if (factTable != null) - factTable = factTable.toUpperCase(); - - for (DimensionDesc dim : dimensions) { - dim.init(tables); - } - - sortDimAndMeasure(); - - initJoinColumns(tables); - initDimensionColumns(tables); - initMeasureColumns(tables); - - /** TODO: should do the initialization after conver - rowkey.init(this); - if (hbaseMapping != null) { - hbaseMapping.init(this); - } - */ - initMeasureReferenceToColumnFamily(); - - if (null != this.cubePartitionDesc) { - this.cubePartitionDesc.init(columnMap); - } - - // check all dimension columns are presented on rowkey - List<TblColRef> dimCols = listDimensionColumnsExcludingDerived(); - if (rowkey.getRowKeyColumns().length != dimCols.size()) { - addError("RowKey columns count (" + rowkey.getRowKeyColumns().length + ") does not match dimension columns count (" + dimCols.size() + "). "); - } - } - - private void initDimensionColumns(Map<String, TableDesc> tables) { - // fill back ColRefDesc - for (DimensionDesc dim : dimensions) { - TableDesc dimTable = tables.get(dim.getTable()); - JoinDesc join = dim.getJoin(); - - ArrayList<TblColRef> dimColList = new ArrayList<TblColRef>(); - ArrayList<TblColRef> hostColList = new ArrayList<TblColRef>(); - - // dimension column - if (dim.getColumn() != null) { - if ("{FK}".equals(dim.getColumn())) { - for (TblColRef ref : join.getForeignKeyColumns()) { - TblColRef inited = initDimensionColRef(ref); - dimColList.add(inited); - hostColList.add(inited); - } - } else { - TblColRef ref = initDimensionColRef(dimTable, dim.getColumn()); - dimColList.add(ref); - hostColList.add(ref); - } - } - // hierarchy columns - if (dim.getHierarchy() != null) { - for (HierarchyDesc hier : dim.getHierarchy()) { - TblColRef ref = initDimensionColRef(dimTable, hier.getColumn()); - hier.setColumnRef(ref); - dimColList.add(ref); - } - if (hostColList.isEmpty()) { // the last hierarchy could serve - // as host when col is - // unspecified - hostColList.add(dimColList.get(dimColList.size() - 1)); - } - } - TblColRef[] dimCols = (TblColRef[]) dimColList.toArray(new TblColRef[dimColList.size()]); - dim.setColumnRefs(dimCols); - - // lookup derived columns - TblColRef[] hostCols = (TblColRef[]) hostColList.toArray(new TblColRef[hostColList.size()]); - String[] derived = dim.getDerived(); - if (derived != null) { - String[][] split = splitDerivedColumnAndExtra(derived); - String[] derivedNames = split[0]; - String[] derivedExtra = split[1]; - TblColRef[] derivedCols = new TblColRef[derivedNames.length]; - for (int i = 0; i < derivedNames.length; i++) { - derivedCols[i] = initDimensionColRef(dimTable, derivedNames[i]); - } - initDerivedMap(hostCols, DeriveType.LOOKUP, dim, derivedCols, derivedExtra); - } - - // FK derived column - if (join != null) { - TblColRef[] fk = join.getForeignKeyColumns(); - TblColRef[] pk = join.getPrimaryKeyColumns(); - for (int i = 0; i < fk.length; i++) { - int find = ArrayUtils.indexOf(hostCols, fk[i]); - if (find >= 0) { - TblColRef derivedCol = initDimensionColRef(pk[i]); - initDerivedMap(hostCols[find], DeriveType.PK_FK, dim, derivedCol); - } - } - for (int i = 0; i < pk.length; i++) { - int find = ArrayUtils.indexOf(hostCols, pk[i]); - if (find >= 0) { - TblColRef derivedCol = initDimensionColRef(fk[i]); - initDerivedMap(hostCols[find], DeriveType.PK_FK, dim, derivedCol); - } - } - } - } - } - - private String[][] splitDerivedColumnAndExtra(String[] derived) { - String[] cols = new String[derived.length]; - String[] extra = new String[derived.length]; - for (int i = 0; i < derived.length; i++) { - String str = derived[i]; - int cut = str.indexOf(":"); - if (cut >= 0) { - cols[i] = str.substring(0, cut); - extra[i] = str.substring(cut + 1).trim(); - } else { - cols[i] = str; - extra[i] = ""; - } - } - return new String[][] { cols, extra }; - } - - private void initDerivedMap(TblColRef hostCol, DeriveType type, DimensionDesc dimension, TblColRef derivedCol) { - initDerivedMap(new TblColRef[] { hostCol }, type, dimension, new TblColRef[] { derivedCol }, null); - } - - private void initDerivedMap(TblColRef[] hostCols, DeriveType type, DimensionDesc dimension, TblColRef[] derivedCols, String[] extra) { - if (hostCols.length == 0 || derivedCols.length == 0) - throw new IllegalStateException("host/derived columns must not be empty"); - - Array<TblColRef> hostColArray = new Array<TblColRef>(hostCols); - List<DeriveInfo> infoList = hostToDerivedMap.get(hostColArray); - if (infoList == null) { - hostToDerivedMap.put(hostColArray, infoList = new ArrayList<DeriveInfo>()); - } - infoList.add(new DeriveInfo(type, dimension, derivedCols, false)); - - for (int i = 0; i < derivedCols.length; i++) { - TblColRef derivedCol = derivedCols[i]; - boolean isOneToOne = type == DeriveType.PK_FK || ArrayUtils.contains(hostCols, derivedCol) || (extra != null && extra[i].contains("1-1")); - derivedToHostMap.put(derivedCol, new DeriveInfo(type, dimension, hostCols, isOneToOne)); - } - } - - private TblColRef initDimensionColRef(TableDesc table, String colName) { - ColumnDesc col = table.findColumnByName(colName); - if (col == null) - throw new IllegalArgumentException("No column '" + colName + "' found in table " + table); - - TblColRef ref = new TblColRef(col); - return initDimensionColRef(ref); - } - - private TblColRef initDimensionColRef(TblColRef ref) { - TblColRef existing = findColumnRef(ref.getTable(), ref.getName()); - if (existing != null) { - return existing; - } - - allColumns.add(ref); - dimensionColumns.add(ref); - - Map<String, TblColRef> cols = columnMap.get(ref.getTable()); - if (cols == null) { - columnMap.put(ref.getTable(), cols = new HashMap<String, TblColRef>()); - } - cols.put(ref.getName(), ref); - return ref; - } - - private void initJoinColumns(Map<String, TableDesc> tables) { - // join columns may or may not present in cube; - // here we don't modify 'allColumns' and 'dimensionColumns'; - // initDimensionColumns() will do the update - for (DimensionDesc dim : dimensions) { - TableDesc dimTable = tables.get(dim.getTable()); - - JoinDesc join = dim.getJoin(); - if (join == null) - continue; - - // primary key - String[] pks = join.getPrimaryKey(); - TblColRef[] pkCols = new TblColRef[pks.length]; - for (int i = 0; i < pks.length; i++) { - ColumnDesc col = dimTable.findColumnByName(pks[i]); - if (col == null) { - addError("Can't find column " + pks[i] + " in table " + dimTable.getName()); - } - TblColRef colRef = new TblColRef(col); - pks[i] = colRef.getName(); - pkCols[i] = colRef; - } - join.setPrimaryKeyColumns(pkCols); - // foreign key - TableDesc factTable = tables.get(this.factTable); - if (factTable == null) { - addError("Fact table does not exist:" + this.factTable); - } - String[] fks = join.getForeignKey(); - TblColRef[] fkCols = new TblColRef[fks.length]; - for (int i = 0; i < fks.length; i++) { - ColumnDesc col = factTable.findColumnByName(fks[i]); - if (col == null) { - addError("Can't find column " + fks[i] + " in table " + this.factTable); - } - TblColRef colRef = new TblColRef(col); - fks[i] = colRef.getName(); - fkCols[i] = colRef; - } - join.setForeignKeyColumns(fkCols); - // Validate join in dimension - if (pkCols.length != fkCols.length) { - addError("Primary keys(" + dim.getTable() + ")" + Arrays.toString(pks) + " are not consistent with Foreign keys(" + this.factTable + ") " + Arrays.toString(fks)); - } - for (int i = 0; i < fkCols.length; i++) { - if (!fkCols[i].getDatatype().equals(pkCols[i].getDatatype())) { - addError("Primary key " + dim.getTable() + "." + pkCols[i].getName() + "." + pkCols[i].getDatatype() + " are not consistent with Foreign key " + this.factTable + "." + fkCols[i].getName() + "." + fkCols[i].getDatatype()); - } - } - - } - } - - private void initMeasureColumns(Map<String, TableDesc> tables) { - if (measures == null || measures.isEmpty()) { - return; - } - - TableDesc factTable = tables.get(getFactTable()); - for (MeasureDesc m : measures) { - m.setName(m.getName().toUpperCase()); - - if (m.getDependentMeasureRef() != null) { - m.setDependentMeasureRef(m.getDependentMeasureRef().toUpperCase()); - } - - FunctionDesc f = m.getFunction(); - f.setExpression(f.getExpression().toUpperCase()); - f.initReturnDataType(); - - ParameterDesc p = f.getParameter(); - - if (p.isColumnType()) { - ArrayList<TblColRef> colRefs = Lists.newArrayList(); - for (String cName : p.getValue().split("\\s*,\\s*")) { - ColumnDesc sourceColumn = factTable.findColumnByName(cName); - TblColRef colRef = new TblColRef(sourceColumn); - colRefs.add(colRef); - allColumns.add(colRef); - } - if (colRefs.isEmpty() == false) - p.setColRefs(colRefs); - } - } - } - - private void initMeasureReferenceToColumnFamily() { - if (measures == null || measures.size() == 0) - return; - - Map<String, MeasureDesc> measureCache = new HashMap<String, MeasureDesc>(); - for (MeasureDesc m : measures) - measureCache.put(m.getName(), m); - - for (HBaseColumnFamilyDesc cf : getHBaseMapping().getColumnFamily()) { - for (HBaseColumnDesc c : cf.getColumns()) { - MeasureDesc[] measureDescs = new MeasureDesc[c.getMeasureRefs().length]; - for (int i = 0; i < c.getMeasureRefs().length; i++) { - measureDescs[i] = measureCache.get(c.getMeasureRefs()[i]); - } - c.setMeasures(measureDescs); - c.setColumnFamilyName(cf.getName()); - } - } - } - - private void sortDimAndMeasure() { - sortDimensionsByID(); - sortMeasuresByID(); - for (DimensionDesc dim : dimensions) { - sortHierarchiesByLevel(dim.getHierarchy()); - } - } - - private void sortDimensionsByID() { - Collections.sort(dimensions, new Comparator<DimensionDesc>() { - @Override - public int compare(DimensionDesc d1, DimensionDesc d2) { - Integer id1 = d1.getId(); - Integer id2 = d2.getId(); - return id1.compareTo(id2); - } - }); - } - - private void sortMeasuresByID() { - if (measures == null) { - measures = Lists.newArrayList(); - } - - Collections.sort(measures, new Comparator<MeasureDesc>() { - @Override - public int compare(MeasureDesc m1, MeasureDesc m2) { - Integer id1 = m1.getId(); - Integer id2 = m2.getId(); - return id1.compareTo(id2); - } - }); - } - - private void sortHierarchiesByLevel(HierarchyDesc[] hierarchies) { - if (hierarchies != null) { - Arrays.sort(hierarchies, new Comparator<HierarchyDesc>() { - @Override - public int compare(HierarchyDesc h1, HierarchyDesc h2) { - Integer level1 = Integer.parseInt(h1.getLevel()); - Integer level2 = Integer.parseInt(h2.getLevel()); - return level1.compareTo(level2); - } - }); - } - } - - - /** - * Add error info and thrown exception out - * - * @param message - */ - public void addError(String message) { - addError(message, false); - } - - /** - * @param message - * error message - * @param silent - * if throw exception - */ - public void addError(String message, boolean silent) { - if (!silent) { - throw new IllegalStateException(message); - } else { - this.errors.add(message); - } - } - - public List<String> getError() { - return this.errors; - } - -}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeInstance.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeInstance.java b/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeInstance.java deleted file mode 100644 index 9778ab7..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeInstance.java +++ /dev/null @@ -1,427 +0,0 @@ -/* - * 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.kylin.cube.model.v1; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.apache.kylin.common.KylinConfig; -import org.apache.kylin.common.persistence.ResourceStore; -import org.apache.kylin.common.persistence.RootPersistentEntity; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonManagedReference; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Objects; -import com.google.common.collect.Lists; - -@JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) -public class CubeInstance extends RootPersistentEntity { - - public static CubeInstance create(String cubeName, String projectName, CubeDesc cubeDesc) { - CubeInstance cubeInstance = new CubeInstance(); - - cubeInstance.setConfig(cubeDesc.getConfig()); - cubeInstance.setName(cubeName); - cubeInstance.setDescName(cubeDesc.getName()); - cubeInstance.setCreateTime(formatTime(System.currentTimeMillis())); - cubeInstance.setSegments(new ArrayList<CubeSegment>()); - cubeInstance.setStatus(CubeStatusEnum.DISABLED); - cubeInstance.updateRandomUuid(); - - return cubeInstance; - } - - @JsonIgnore - private KylinConfig config; - @JsonProperty("name") - private String name; - @JsonProperty("owner") - private String owner; - @JsonProperty("version") - private String version; // user info only, we don't do version control - @JsonProperty("descriptor") - private String descName; - // Mark cube priority for query - @JsonProperty("cost") - private int cost = 50; - @JsonProperty("status") - private CubeStatusEnum status; - - @JsonManagedReference - @JsonProperty("segments") - private List<CubeSegment> segments = new ArrayList<CubeSegment>(); - - @JsonProperty("create_time") - private String createTime; - - public List<CubeSegment> getBuildingSegments() { - List<CubeSegment> buildingSegments = new ArrayList<CubeSegment>(); - if (null != segments) { - for (CubeSegment segment : segments) { - if (CubeSegmentStatusEnum.NEW == segment.getStatus() || CubeSegmentStatusEnum.READY_PENDING == segment.getStatus()) { - buildingSegments.add(segment); - } - } - } - - return buildingSegments; - } - - public long getAllocatedEndDate() { - if (null == segments || segments.size() == 0) { - return 0; - } - - Collections.sort(segments); - - return segments.get(segments.size() - 1).getDateRangeEnd(); - } - - public long getAllocatedStartDate() { - if (null == segments || segments.size() == 0) { - return 0; - } - - Collections.sort(segments); - - return segments.get(0).getDateRangeStart(); - } - - public List<CubeSegment> getMergingSegments() { - return this.getMergingSegments(null); - } - - public List<CubeSegment> getMergingSegments(CubeSegment cubeSegment) { - CubeSegment buildingSegment; - if (cubeSegment == null) { - List<CubeSegment> buildingSegments = getBuildingSegments(); - if (buildingSegments.size() == 0) { - return Collections.emptyList(); - } - buildingSegment = buildingSegments.get(0); - } else { - buildingSegment = cubeSegment; - } - - List<CubeSegment> mergingSegments = new ArrayList<CubeSegment>(); - if (null != this.segments) { - for (CubeSegment segment : this.segments) { - if (segment.getStatus() == CubeSegmentStatusEnum.READY) { - if (buildingSegment.getDateRangeStart() <= segment.getDateRangeStart() && buildingSegment.getDateRangeEnd() >= segment.getDateRangeEnd()) { - mergingSegments.add(segment); - } - } - } - } - return mergingSegments; - - } - - public List<CubeSegment> getRebuildingSegments() { - List<CubeSegment> buildingSegments = getBuildingSegments(); - if (buildingSegments.size() == 0) { - return Collections.emptyList(); - } else { - List<CubeSegment> rebuildingSegments = new ArrayList<CubeSegment>(); - if (null != this.segments) { - long startDate = buildingSegments.get(0).getDateRangeStart(); - long endDate = buildingSegments.get(buildingSegments.size() - 1).getDateRangeEnd(); - for (CubeSegment segment : this.segments) { - if (segment.getStatus() == CubeSegmentStatusEnum.READY) { - if (startDate >= segment.getDateRangeStart() && startDate < segment.getDateRangeEnd() && segment.getDateRangeEnd() < endDate) { - rebuildingSegments.add(segment); - continue; - } - if (startDate <= segment.getDateRangeStart() && endDate >= segment.getDateRangeEnd()) { - rebuildingSegments.add(segment); - continue; - } - } - } - } - - return rebuildingSegments; - } - } - - // public CubeDesc getDescriptor() { - // return CubeDescManager.getInstance(config).getCubeDesc(descName); - // } - - public boolean isReady() { - return getStatus() == CubeStatusEnum.READY; - } - - public String getResourcePath() { - return concatResourcePath(name); - } - - public static String concatResourcePath(String cubeName) { - return ResourceStore.CUBE_RESOURCE_ROOT + "/" + cubeName + ".json"; - } - - @Override - public String toString() { - return "Cube [name=" + name + "]"; - } - - // ============================================================================ - - @JsonProperty("size_kb") - public long getSizeKB() { - long sizeKb = 0L; - - for (CubeSegment cubeSegment : this.getSegments(CubeSegmentStatusEnum.READY)) { - sizeKb += cubeSegment.getSizeKB(); - } - - return sizeKb; - } - - @JsonProperty("source_records_count") - public long getSourceRecordCount() { - long sizeRecordCount = 0L; - - for (CubeSegment cubeSegment : this.getSegments(CubeSegmentStatusEnum.READY)) { - sizeRecordCount += cubeSegment.getSourceRecords(); - } - - return sizeRecordCount; - } - - @JsonProperty("source_records_size") - public long getSourceRecordSize() { - long sizeRecordSize = 0L; - - for (CubeSegment cubeSegment : this.getSegments(CubeSegmentStatusEnum.READY)) { - sizeRecordSize += cubeSegment.getSourceRecordsSize(); - } - - return sizeRecordSize; - } - - public KylinConfig getConfig() { - return config; - } - - public void setConfig(KylinConfig config) { - this.config = config; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getDescName() { - return descName.toUpperCase(); - } - - public String getOriginDescName() { - return descName; - } - - public void setDescName(String descName) { - this.descName = descName; - } - - public int getCost() { - return cost; - } - - public void setCost(int cost) { - this.cost = cost; - } - - public CubeStatusEnum getStatus() { - return status; - } - - public void setStatus(CubeStatusEnum status) { - this.status = status; - } - - public CubeSegment getFirstSegment() { - if (this.segments == null || this.segments.size() == 0) { - return null; - } else { - return this.segments.get(0); - } - } - - public CubeSegment getLatestReadySegment() { - CubeSegment latest = null; - for (int i = segments.size() - 1; i >= 0; i--) { - CubeSegment seg = segments.get(i); - if (seg.getStatus() != CubeSegmentStatusEnum.READY) - continue; - if (latest == null || latest.getDateRangeEnd() < seg.getDateRangeEnd()) { - latest = seg; - } - } - return latest; - } - - public List<CubeSegment> getSegments() { - return segments; - } - - public List<CubeSegment> getSegments(CubeSegmentStatusEnum status) { - List<CubeSegment> result = new ArrayList<CubeSegment>(); - - for (CubeSegment segment : segments) { - if (segment.getStatus() == status) { - result.add(segment); - } - } - - return result; - } - - public List<CubeSegment> getSegment(CubeSegmentStatusEnum status) { - List<CubeSegment> result = Lists.newArrayList(); - for (CubeSegment segment : segments) { - if (segment.getStatus() == status) { - result.add(segment); - } - } - return result; - } - - public CubeSegment getSegment(String name, CubeSegmentStatusEnum status) { - for (CubeSegment segment : segments) { - if ((null != segment.getName() && segment.getName().equals(name)) && segment.getStatus() == status) { - return segment; - } - } - - return null; - } - - public void setSegments(List<CubeSegment> segments) { - this.segments = segments; - } - - public CubeSegment getSegmentById(String segmentId) { - for (CubeSegment segment : segments) { - if (Objects.equal(segment.getUuid(), segmentId)) { - return segment; - } - } - return null; - } - - public String getCreateTime() { - return createTime; - } - - public void setCreateTime(String createTime) { - this.createTime = createTime; - } - - public long[] getDateRange() { - List<CubeSegment> readySegments = getSegment(CubeSegmentStatusEnum.READY); - if (readySegments.isEmpty()) { - return new long[] { 0L, 0L }; - } - long start = Long.MAX_VALUE; - long end = Long.MIN_VALUE; - for (CubeSegment segment : readySegments) { - if (segment.getDateRangeStart() < start) { - start = segment.getDateRangeStart(); - } - if (segment.getDateRangeEnd() > end) { - end = segment.getDateRangeEnd(); - } - } - return new long[] { start, end }; - } - - // private boolean appendOnHll() { - // CubePartitionDesc cubePartitionDesc = getDescriptor().getCubePartitionDesc(); - // if (cubePartitionDesc == null) { - // return false; - // } - // if (cubePartitionDesc.getPartitionDateColumn() == null) { - // return false; - // } - // if (cubePartitionDesc.getCubePartitionType() != CubePartitionDesc.CubePartitionType.APPEND) { - // return false; - // } - // return getDescriptor().hasHolisticCountDistinctMeasures(); - // } - - // public boolean appendBuildOnHllMeasure(long startDate, long endDate) { - // if (!appendOnHll()) { - // return false; - // } - // List<CubeSegment> readySegments = getSegment(CubeSegmentStatusEnum.READY); - // if (readySegments.isEmpty()) { - // return false; - // } - // for (CubeSegment readySegment: readySegments) { - // if (readySegment.getDateRangeStart() == startDate && readySegment.getDateRangeEnd() == endDate) { - // //refresh build - // return false; - // } - // } - // return true; - // } - - // public boolean needMergeImmediatelyAfterBuild(CubeSegment segment) { - // if (!appendOnHll()) { - // return false; - // } - // List<CubeSegment> readySegments = getSegment(CubeSegmentStatusEnum.READY); - // if (readySegments.isEmpty()) { - // return false; - // } - // for (CubeSegment readySegment: readySegments) { - // if (readySegment.getDateRangeEnd() > segment.getDateRangeStart()) { - // //has overlap and not refresh - // return true; - // } - // } - // return false; - // } - -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/v1/CubePartitionDesc.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubePartitionDesc.java b/cube/src/main/java/org/apache/kylin/cube/model/v1/CubePartitionDesc.java deleted file mode 100644 index 83e1758..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubePartitionDesc.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.kylin.cube.model.v1; - -import java.util.Map; - -import org.apache.kylin.metadata.model.TblColRef; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * @author xduo - * - */ -@JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) -public class CubePartitionDesc { - - public static enum CubePartitionType { - APPEND, UPDATE_INSERT - } - - @JsonProperty("partition_date_column") - private String partitionDateColumn; - @JsonProperty("partition_date_start") - private long partitionDateStart = 0L; - @JsonProperty("cube_partition_type") - private CubePartitionType cubePartitionType = CubePartitionType.APPEND; - - private TblColRef partitionDateColumnRef; - - public void init(Map<String, Map<String, TblColRef>> columnMap) { - if (null != partitionDateColumn) { - String[] columns = partitionDateColumn.split("\\."); - - if (null != columns && columns.length == 2) { - Map<String, TblColRef> cols = columnMap.get(columns[0].toUpperCase()); - if (cols != null) - partitionDateColumnRef = cols.get(columns[1].toUpperCase()); - - } - } - } - - public boolean isPartitioned() { - return partitionDateColumnRef != null; - } - - public String getPartitionDateColumn() { - return partitionDateColumn; - } - - public void setPartitionDateColumn(String partitionDateColumn) { - this.partitionDateColumn = partitionDateColumn; - } - - public long getPartitionDateStart() { - return partitionDateStart; - } - - public void setPartitionDateStart(long partitionDateStart) { - this.partitionDateStart = partitionDateStart; - } - - public CubePartitionType getCubePartitionType() { - return cubePartitionType; - } - - public void setCubePartitionType(CubePartitionType cubePartitionType) { - this.cubePartitionType = cubePartitionType; - } - - public TblColRef getPartitionDateColumnRef() { - return partitionDateColumnRef; - } - -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegment.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegment.java b/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegment.java deleted file mode 100644 index 83ef94c..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegment.java +++ /dev/null @@ -1,303 +0,0 @@ -/* - * 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.kylin.cube.model.v1; - -import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Map; -import java.util.TimeZone; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.kylin.metadata.model.TblColRef; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; -import com.fasterxml.jackson.annotation.JsonBackReference; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Objects; - -@JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) -public class CubeSegment implements Comparable<CubeSegment> { - - @JsonBackReference - private CubeInstance cubeInstance; - @JsonProperty("uuid") - private String uuid; - @JsonProperty("name") - private String name; - @JsonProperty("storage_location_identifier") - private String storageLocationIdentifier; // HTable name - @JsonProperty("date_range_start") - private long dateRangeStart; - @JsonProperty("date_range_end") - private long dateRangeEnd; - @JsonProperty("status") - private CubeSegmentStatusEnum status; - @JsonProperty("size_kb") - private long sizeKB; - @JsonProperty("source_records") - private long sourceRecords; - @JsonProperty("source_records_size") - private long sourceRecordsSize; - @JsonProperty("last_build_time") - private long lastBuildTime; - @JsonProperty("last_build_job_id") - private String lastBuildJobID; - @JsonProperty("create_time") - private String createTime; - - @JsonProperty("binary_signature") - private String binarySignature; // a hash of cube schema and dictionary ID, - // used for sanity check - - @JsonProperty("dictionaries") - private ConcurrentHashMap<String, String> dictionaries; // table/column ==> dictionary resource path - @JsonProperty("snapshots") - private ConcurrentHashMap<String, String> snapshots; // table name ==> snapshot resource path - - // public CubeDesc getCubeDesc() { - // return getCubeInstance().getDescriptor(); - // } - - /** - * @param startDate - * @param endDate - * @return if(startDate == 0 && endDate == 0), returns "FULL_BUILD", else - * returns "yyyyMMddHHmmss_yyyyMMddHHmmss" - */ - public static String getSegmentName(long startDate, long endDate) { - if (startDate == 0 && endDate == 0) { - return "FULL_BUILD"; - } - - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); - dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); - - return dateFormat.format(startDate) + "_" + dateFormat.format(endDate); - } - - // ============================================================================ - - public String getUuid() { - return uuid; - } - - public void setUuid(String id) { - this.uuid = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public long getDateRangeStart() { - return dateRangeStart; - } - - public void setDateRangeStart(long dateRangeStart) { - this.dateRangeStart = dateRangeStart; - } - - public long getDateRangeEnd() { - return dateRangeEnd; - } - - public void setDateRangeEnd(long dateRangeEnd) { - this.dateRangeEnd = dateRangeEnd; - } - - public CubeSegmentStatusEnum getStatus() { - return status; - } - - public void setStatus(CubeSegmentStatusEnum status) { - this.status = status; - } - - public long getSizeKB() { - return sizeKB; - } - - public void setSizeKB(long sizeKB) { - this.sizeKB = sizeKB; - } - - public long getSourceRecords() { - return sourceRecords; - } - - public void setSourceRecords(long sourceRecords) { - this.sourceRecords = sourceRecords; - } - - public long getSourceRecordsSize() { - return sourceRecordsSize; - } - - public void setSourceRecordsSize(long sourceRecordsSize) { - this.sourceRecordsSize = sourceRecordsSize; - } - - public long getLastBuildTime() { - return lastBuildTime; - } - - public void setLastBuildTime(long lastBuildTime) { - this.lastBuildTime = lastBuildTime; - } - - public String getLastBuildJobID() { - return lastBuildJobID; - } - - public void setLastBuildJobID(String lastBuildJobID) { - this.lastBuildJobID = lastBuildJobID; - } - - public String getCreateTime() { - return createTime; - } - - public void setCreateTime(String createTime) { - this.createTime = createTime; - } - - public String getBinarySignature() { - return binarySignature; - } - - public void setBinarySignature(String binarySignature) { - this.binarySignature = binarySignature; - } - - public CubeInstance getCubeInstance() { - return cubeInstance; - } - - public void setCubeInstance(CubeInstance cubeInstance) { - this.cubeInstance = cubeInstance; - } - - public String getStorageLocationIdentifier() { - - return storageLocationIdentifier; - } - - public Map<String, String> getDictionaries() { - if (dictionaries == null) - dictionaries = new ConcurrentHashMap<String, String>(); - return dictionaries; - } - - public Map<String, String> getSnapshots() { - if (snapshots == null) - snapshots = new ConcurrentHashMap<String, String>(); - return snapshots; - } - - public String getSnapshotResPath(String table) { - return getSnapshots().get(table); - } - - public void putSnapshotResPath(String table, String snapshotResPath) { - getSnapshots().put(table, snapshotResPath); - } - - public Collection<String> getDictionaryPaths() { - return getDictionaries().values(); - } - - public Collection<String> getSnapshotPaths() { - return getSnapshots().values(); - } - - public String getDictResPath(TblColRef col) { - return getDictionaries().get(dictKey(col)); - } - - public void putDictResPath(TblColRef col, String dictResPath) { - getDictionaries().put(dictKey(col), dictResPath); - } - - private String dictKey(TblColRef col) { - return col.getTable() + "/" + col.getName(); - } - - /** - * @param storageLocationIdentifier - * the storageLocationIdentifier to set - */ - public void setStorageLocationIdentifier(String storageLocationIdentifier) { - this.storageLocationIdentifier = storageLocationIdentifier; - } - - @Override - public int compareTo(CubeSegment other) { - if (this.dateRangeEnd < other.dateRangeEnd) { - return -1; - } else if (this.dateRangeEnd > other.dateRangeEnd) { - return 1; - } else { - return 0; - } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((cubeInstance == null) ? 0 : cubeInstance.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - CubeSegment other = (CubeSegment) obj; - if (cubeInstance == null) { - if (other.cubeInstance != null) - return false; - } else if (!cubeInstance.equals(other.cubeInstance)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (status != other.status) - return false; - return true; - } - - @Override - public String toString() { - return Objects.toStringHelper(this).add("uuid", uuid).add("create_time:", createTime).add("name", name).add("last_build_job_id", lastBuildJobID).add("status", status).toString(); - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegmentStatusEnum.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegmentStatusEnum.java b/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegmentStatusEnum.java deleted file mode 100644 index 62346f8..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegmentStatusEnum.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.kylin.cube.model.v1; - -/** - * @author xduo - * - */ -public enum CubeSegmentStatusEnum { - NEW, READY, READY_PENDING -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegmentTypeEnum.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegmentTypeEnum.java b/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegmentTypeEnum.java deleted file mode 100644 index 3b7350d..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeSegmentTypeEnum.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.kylin.cube.model.v1; - -/** - * @author ysong1 - * - */ -public enum CubeSegmentTypeEnum { - TRANSIENT, PERMANENT -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeStatusEnum.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeStatusEnum.java b/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeStatusEnum.java deleted file mode 100644 index 58bf92b..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/v1/CubeStatusEnum.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.kylin.cube.model.v1; - -public enum CubeStatusEnum { - - DISABLED, BUILDING, READY, DESCBROKEN - -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/v1/DimensionDesc.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/v1/DimensionDesc.java b/cube/src/main/java/org/apache/kylin/cube/model/v1/DimensionDesc.java deleted file mode 100644 index ace1e3e..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/v1/DimensionDesc.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * 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.kylin.cube.model.v1; - -import java.util.Arrays; -import java.util.Map; - -import org.apache.kylin.common.util.StringUtil; -import org.apache.kylin.cube.model.HierarchyDesc; -import org.apache.kylin.metadata.model.JoinDesc; -import org.apache.kylin.metadata.model.TableDesc; -import org.apache.kylin.metadata.model.TblColRef; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created with IntelliJ IDEA. User: lukhan Date: 9/24/13 Time: 10:40 AM To - * change this template use File | Settings | File Templates. - */ -@JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) -public class DimensionDesc { - - @JsonProperty("id") - private int id; - @JsonProperty("name") - private String name; - @JsonProperty("join") - private JoinDesc join; - @JsonProperty("hierarchy") - private HierarchyDesc[] hierarchy; - @JsonProperty("table") - private String table; - @JsonProperty("column") - private String column; - @JsonProperty("datatype") - private String datatype; - @JsonProperty("derived") - private String[] derived; - - // computed - private TblColRef[] columnRefs; - private TblColRef[] derivedColRefs; - - public boolean isHierarchyColumn(TblColRef col) { - if (hierarchy == null) - return false; - - for (HierarchyDesc hier : hierarchy) { - if (hier.getColumnRef().equals(col)) - return true; - } - return false; - } - - public String getDatatype() { - return datatype; - } - - public void setDatatype(String datatype) { - this.datatype = datatype; - } - - public String getTable() { - return table.toUpperCase(); - } - - public void setTable(String table) { - this.table = table; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public JoinDesc getJoin() { - return join; - } - - public void setJoin(JoinDesc join) { - this.join = join; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public TblColRef[] getColumnRefs() { - return this.columnRefs; - } - - public void setColumnRefs(TblColRef[] colRefs) { - this.columnRefs = colRefs; - } - - public String getColumn() { - return this.column; - } - - public void setColumn(String column) { - this.column = column; - if (this.column != null) - this.column = this.column.toUpperCase(); - } - - public HierarchyDesc[] getHierarchy() { - return hierarchy; - } - - public void setHierarchy(HierarchyDesc[] hierarchy) { - this.hierarchy = hierarchy; - } - - public String[] getDerived() { - return derived; - } - - public void setDerived(String[] derived) { - this.derived = derived; - } - - public TblColRef[] getDerivedColRefs() { - return derivedColRefs; - } - - public void setDerivedColRefs(TblColRef[] derivedColRefs) { - this.derivedColRefs = derivedColRefs; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - DimensionDesc that = (DimensionDesc) o; - - if (id != that.id) - return false; - if (!name.equals(that.name)) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = id; - result = 31 * result + name.hashCode(); - return result; - } - - @Override - public String toString() { - return "DimensionDesc [name=" + name + ", join=" + join + ", hierarchy=" + Arrays.toString(hierarchy) + ", table=" + table + ", column=" + column + ", datatype=" + datatype + ", derived=" + Arrays.toString(derived) + "]"; - } - - public void init(Map<String, TableDesc> tables) { - if (name != null) - name = name.toUpperCase(); - if (table != null) - table = table.toUpperCase(); - if (column != null) - column = column.toUpperCase(); - - TableDesc tableDesc = tables.get(table); - if (tableDesc == null) - throw new IllegalStateException("Can't find table " + table + " on dimension " + name); - - if (hierarchy != null && hierarchy.length == 0) - hierarchy = null; - if (derived != null && derived.length == 0) - derived = null; - - if (join != null) { - StringUtil.toUpperCaseArray(join.getForeignKey(), join.getForeignKey()); - StringUtil.toUpperCaseArray(join.getPrimaryKey(), join.getPrimaryKey()); - } - - if (hierarchy != null) { - for (HierarchyDesc h : hierarchy) - h.setColumn(h.getColumn().toUpperCase()); - } - - if (derived != null) { - StringUtil.toUpperCaseArray(derived, derived); - } - } - -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/v1/ProjectInstance.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/v1/ProjectInstance.java b/cube/src/main/java/org/apache/kylin/cube/model/v1/ProjectInstance.java deleted file mode 100644 index cb551c2..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/v1/ProjectInstance.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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.kylin.cube.model.v1; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -import org.apache.kylin.common.persistence.ResourceStore; -import org.apache.kylin.common.persistence.RootPersistentEntity; -import org.apache.kylin.metadata.project.ProjectStatusEnum; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Project is a concept in Kylin similar to schema in DBMS - */ -@JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) -public class ProjectInstance extends RootPersistentEntity { - - public static final String DEFAULT_PROJECT_NAME = "DEFAULT"; - - @JsonProperty("name") - private String name; - - @JsonProperty("cubes") - private List<String> cubes; - - @JsonProperty("tables") - private Set<String> tables; - - @JsonProperty("owner") - private String owner; - - @JsonProperty("status") - private ProjectStatusEnum status; - - @JsonProperty("create_time") - private String createTime; - - @JsonProperty("last_update_time") - private String lastUpdateTime; - - @JsonProperty("description") - private String description; - - public String getResourcePath() { - return concatResourcePath(name); - } - - public static String concatResourcePath(String projectName) { - return ResourceStore.PROJECT_RESOURCE_ROOT + "/" + projectName + ".json"; - } - - public static String getNormalizedProjectName(String project) { - if (project == null) - throw new IllegalStateException("Trying to normalized a project name which is null"); - - return project.toUpperCase(); - } - - // ============================================================================ - - public static ProjectInstance create(String name, String owner, String description, List<String> cubes) { - ProjectInstance projectInstance = new ProjectInstance(); - - projectInstance.updateRandomUuid(); - projectInstance.setName(name); - projectInstance.setOwner(owner); - projectInstance.setDescription(description); - projectInstance.setStatus(ProjectStatusEnum.ENABLED); - projectInstance.setCreateTime(formatTime(System.currentTimeMillis())); - if (cubes != null) - projectInstance.setCubes(cubes); - else - projectInstance.setCubes(new ArrayList<String>()); - - return projectInstance; - } - - public ProjectInstance() { - - } - - public ProjectInstance(String name, List<String> cubes, String owner) { - this.name = name; - this.cubes = cubes; - this.owner = owner; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public ProjectStatusEnum getStatus() { - return status; - } - - public void setStatus(ProjectStatusEnum status) { - this.status = status; - } - - public String getCreateTime() { - return createTime; - } - - public void setCreateTime(String createTime) { - this.createTime = createTime; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public boolean containsCube(String cubeName) { - cubeName = cubeName.toUpperCase(); - return cubes.contains(cubeName); - } - - public void removeCube(String cubeName) { - cubeName = cubeName.toUpperCase(); - cubes.remove(cubeName); - } - - public int getCubesCount() { - return cubes.size(); - } - - public void addCube(String cubeName) { - cubeName = cubeName.toUpperCase(); - this.cubes.add(cubeName); - } - - public List<String> getCubes() { - return cubes; - } - - public void setCubes(List<String> cubes) { - this.cubes = cubes; - } - - public void setTables(Set<String> tables) { - this.tables = tables; - } - - public boolean containsTable(String tableName) { - tableName = tableName.toUpperCase(); - return tables.contains(tableName); - } - - public void removeTable(String tableName) { - tableName = tableName.toUpperCase(); - tables.remove(tableName); - } - - public int getTablesCount() { - return this.getTables().size(); - } - - public void addTable(String tableName) { - tableName = tableName.toUpperCase(); - this.getTables().add(tableName); - } - - //will return new Set for null - public Set<String> getTables() { - tables = tables == null ? new TreeSet<String>() : tables; - return tables; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - public String getLastUpdateTime() { - return lastUpdateTime; - } - - public void setLastUpdateTime(String lastUpdateTime) { - this.lastUpdateTime = lastUpdateTime; - } - - public void recordUpdateTime(long timeMillis) { - this.lastUpdateTime = formatTime(timeMillis); - } - - public void init() { - if (name == null) - name = ProjectInstance.DEFAULT_PROJECT_NAME; - - if (cubes == null) { - cubes = new ArrayList<String>(); - } - - for (int i = 0; i < cubes.size(); ++i) { - if (cubes.get(i) != null) - cubes.set(i, cubes.get(i).toUpperCase()); - } - } - - @Override - public String toString() { - return "ProjectDesc [name=" + name + "]"; - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/CubeMetadataValidator.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/CubeMetadataValidator.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/CubeMetadataValidator.java deleted file mode 100644 index 77b1770..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/validation/CubeMetadataValidator.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.kylin.cube.model.validation; - -import org.apache.kylin.cube.model.CubeDesc; -import org.apache.kylin.cube.model.validation.rule.AggregationGroupSizeRule; -import org.apache.kylin.cube.model.validation.rule.FunctionRule; -import org.apache.kylin.cube.model.validation.rule.MandatoryColumnRule; -import org.apache.kylin.cube.model.validation.rule.RowKeyAttrRule; - -/** - * For cube metadata validator - * - * @author jianliu - * - */ -public class CubeMetadataValidator { - @SuppressWarnings("unchecked") - private IValidatorRule<CubeDesc>[] rules = new IValidatorRule[] { new FunctionRule(), new AggregationGroupSizeRule(), new MandatoryColumnRule(), new RowKeyAttrRule() }; - - public ValidateContext validate(CubeDesc cube) { - return validate(cube, false); - } - - /** - * @param cubeDesc - * @param inject - * inject error into cube desc - * @return - */ - public ValidateContext validate(CubeDesc cube, boolean inject) { - ValidateContext context = new ValidateContext(); - for (int i = 0; i < rules.length; i++) { - IValidatorRule<CubeDesc> rule = rules[i]; - rule.validate(cube, context); - } - if (inject) { - injectResult(cube, context); - } - return context; - } - - /** - * - * Inject errors info into cubeDesc - * - * @param cubeDesc - * @param context - */ - public void injectResult(CubeDesc cubeDesc, ValidateContext context) { - ValidateContext.Result[] results = context.getResults(); - for (int i = 0; i < results.length; i++) { - ValidateContext.Result result = results[i]; - cubeDesc.addError(result.getLevel() + " : " + result.getMessage(), true); - } - - } - -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/IValidatorRule.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/IValidatorRule.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/IValidatorRule.java deleted file mode 100644 index 0368528..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/validation/IValidatorRule.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.kylin.cube.model.validation; - -import org.apache.kylin.cube.model.validation.rule.IKylinValidationConstants; - -/** - * @author jianliu - * - */ -public interface IValidatorRule<T> extends IKylinValidationConstants { - - public void validate(T element, ValidateContext context); -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/ResultLevel.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/ResultLevel.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/ResultLevel.java deleted file mode 100644 index 9dcefc5..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/validation/ResultLevel.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.kylin.cube.model.validation; - -/** - * Validation result level - * - * @author jianliu - * - */ -public enum ResultLevel { - ERROR("ERROR"), WARN("WARN"); - private String level; - - ResultLevel(String level) { - this.level = level; - } - - public String toString() { - return level; - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/SourceTableMetadataValidator.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/SourceTableMetadataValidator.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/SourceTableMetadataValidator.java deleted file mode 100644 index 14be1c4..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/validation/SourceTableMetadataValidator.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.kylin.cube.model.validation; - -import org.apache.kylin.metadata.model.TableDesc; - -/** - * Validate Table metadata from source. - * <p/> - * User: lukhan Date: 12/2/13 Time: 10:45 AM To change this template use File | - * Settings | File Templates. - */ -public class SourceTableMetadataValidator { - - public static boolean validate(TableDesc table) { - // table.get - return true; - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/ValidateContext.java ---------------------------------------------------------------------- diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/ValidateContext.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/ValidateContext.java deleted file mode 100644 index 8ac5360..0000000 --- a/cube/src/main/java/org/apache/kylin/cube/model/validation/ValidateContext.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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.kylin.cube.model.validation; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * Context. Supply all dependent objects for validator - * - * @author jianliu - * - */ -public class ValidateContext { - private List<Result> results = new ArrayList<ValidateContext.Result>(); - - public void addResult(ResultLevel level, String message) { - results.add(new Result(level, message)); - } - - public void addResult(Result result) { - results.add(result); - } - - public class Result { - private ResultLevel level; - private String message; - - /** - * @param level - * @param message - */ - public Result(ResultLevel level, String message) { - this.level = level; - this.message = message; - } - - /** - * @return the level - */ - public ResultLevel getLevel() { - return level; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - } - - /** - * Get validation result - * - * @return - */ - public Result[] getResults() { - Result[] rs = new Result[0]; - rs = results.toArray(rs); - return rs; - } - - /** - * - */ - public void print(PrintStream out) { - if (results.isEmpty()) { - out.print("The element is perfect."); - } - Iterator<Result> it = results.iterator(); - while (it.hasNext()) { - Result result = it.next(); - out.println(result.level + " : " + result.message); - } - } - - /** - * @return if there is not validation errors - */ - public boolean ifPass() { - return results.isEmpty(); - } - -}
