You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by lu...@apache.org on 2015/01/14 15:16:14 UTC
[39/51] [partial] incubator-kylin git commit: cleanup for migration
from github.com
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/a4fd4268/cube/src/main/java/com/kylinolap/cube/project/ProjectInstance.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/com/kylinolap/cube/project/ProjectInstance.java b/cube/src/main/java/com/kylinolap/cube/project/ProjectInstance.java
deleted file mode 100644
index 1d4023e..0000000
--- a/cube/src/main/java/com/kylinolap/cube/project/ProjectInstance.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Copyright 2013-2014 eBay Software Foundation
- *
- * Licensed 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 com.kylinolap.cube.project;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.kylinolap.common.persistence.ResourceStore;
-import com.kylinolap.common.persistence.RootPersistentEntity;
-
-/**
- * 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/incubator-kylin/blob/a4fd4268/cube/src/main/java/com/kylinolap/cube/project/ProjectManager.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/com/kylinolap/cube/project/ProjectManager.java b/cube/src/main/java/com/kylinolap/cube/project/ProjectManager.java
deleted file mode 100644
index e05eae2..0000000
--- a/cube/src/main/java/com/kylinolap/cube/project/ProjectManager.java
+++ /dev/null
@@ -1,582 +0,0 @@
-/*
- * Copyright 2013-2014 eBay Software Foundation
- *
- * Licensed 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 com.kylinolap.cube.project;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
-import com.kylinolap.common.KylinConfig;
-import com.kylinolap.common.persistence.JsonSerializer;
-import com.kylinolap.common.persistence.ResourceStore;
-import com.kylinolap.common.persistence.Serializer;
-import com.kylinolap.common.restclient.Broadcaster;
-import com.kylinolap.common.restclient.SingleValueCache;
-import com.kylinolap.cube.CubeInstance;
-import com.kylinolap.cube.CubeManager;
-import com.kylinolap.metadata.MetadataManager;
-import com.kylinolap.metadata.model.cube.CubeDesc;
-import com.kylinolap.metadata.model.cube.DimensionDesc;
-import com.kylinolap.metadata.model.cube.FunctionDesc;
-import com.kylinolap.metadata.model.cube.JoinDesc;
-import com.kylinolap.metadata.model.cube.MeasureDesc;
-import com.kylinolap.metadata.model.cube.TblColRef;
-import com.kylinolap.metadata.model.schema.ColumnDesc;
-import com.kylinolap.metadata.model.schema.TableDesc;
-
-/**
- * @author xduo
- */
-public class ProjectManager {
- private static final Logger logger = LoggerFactory.getLogger(ProjectManager.class);
-
- // static cached instances
- private static final ConcurrentHashMap<KylinConfig, ProjectManager> CACHE = new ConcurrentHashMap<KylinConfig, ProjectManager>();
- private static final Serializer<ProjectInstance> PROJECT_SERIALIZER = new JsonSerializer<ProjectInstance>(ProjectInstance.class);
-
- private KylinConfig config;
- // project name => ProjrectDesc
- private SingleValueCache<String, ProjectInstance> projectMap = new SingleValueCache<String, ProjectInstance>(Broadcaster.TYPE.PROJECT);
- // project name => tables
- private Multimap<String, ProjectTable> projectTables = Multimaps.synchronizedMultimap(HashMultimap.<String, ProjectTable>create());
-
- public static ProjectManager getInstance(KylinConfig config) {
- ProjectManager r = CACHE.get(config);
- if (r != null) {
- return r;
- }
-
- synchronized (ProjectManager.class) {
- r = CACHE.get(config);
- if (r != null) {
- return r;
- }
- try {
- r = new ProjectManager(config);
- CACHE.put(config, r);
- if (CACHE.size() > 1) {
- logger.warn("More than one singleton exist");
- }
- return r;
- } catch (IOException e) {
- throw new IllegalStateException("Failed to init CubeManager from " + config, e);
- }
- }
- }
-
- public static synchronized void removeInstance(KylinConfig config) {
- CACHE.remove(config);
- }
-
- private ProjectManager(KylinConfig config) throws IOException {
- logger.info("Initializing CubeManager with metadata url " + config);
- this.config = config;
-
- loadAllProjects();
- }
-
- public static String getDefaultProjectName() {
- return ProjectInstance.DEFAULT_PROJECT_NAME;
- }
-
- public List<ProjectInstance> listAllProjects() {
- return new ArrayList<ProjectInstance>(projectMap.values());
- }
-
- public List<ProjectInstance> getProjects(String cubeName) {
- return this.findProjects(cubeName);
- }
-
- public ProjectInstance dropProject(String projectName) throws IOException {
- if (projectName == null)
- throw new IllegalArgumentException("Project name not given");
-
- ProjectInstance projectInstance = getProject(projectName);
-
- if (projectInstance == null) {
- throw new IllegalStateException("The project named " + projectName + " does not exist");
- }
-
- if (projectInstance.getCubes().size() != 0) {
- throw new IllegalStateException("The project named " + projectName + " can not be deleted because there's still cubes in it. Delete all the cubes first.");
- }
-
- logger.info("Dropping project '" + projectInstance.getName() + "'");
- deleteResource(projectInstance);
-
- return projectInstance;
- }
-
- public ProjectInstance getProject(String projectName) {
- if (projectName == null)
- return null;
- projectName = ProjectInstance.getNormalizedProjectName(projectName);
- return projectMap.get(projectName);
- }
-
- public ProjectInstance createProject(String projectName, String owner, String description) throws IOException {
-
- logger.info("Creating project '" + projectName);
-
- ProjectInstance currentProject = getProject(projectName);
- if (currentProject == null) {
- currentProject = ProjectInstance.create(projectName, owner, description, null);
- } else {
- throw new IllegalStateException("The project named " + projectName + "already exists");
- }
-
- saveResource(currentProject);
-
- return currentProject;
- }
-
- public ProjectInstance updateProject(ProjectInstance project, String newName, String newDesc) throws IOException {
- if (!project.getName().equals(newName)) {
- ProjectInstance newProject = this.createProject(newName, project.getOwner(), newDesc);
- newProject.setCreateTime(project.getCreateTime());
- newProject.recordUpdateTime(System.currentTimeMillis());
- newProject.setCubes(project.getCubes());
-
- deleteResource(project);
- saveResource(newProject);
-
- return newProject;
- } else {
- project.setName(newName);
- project.setDescription(newDesc);
-
- if (project.getUuid() == null)
- project.updateRandomUuid();
-
- saveResource(project);
-
- return project;
- }
- }
-
- public boolean isCubeInProject(String projectName, CubeInstance cube) {
- return this.listAllCubes(projectName).contains(cube);
- }
-
- public ProjectInstance updateCubeToProject(String cubeName, String newProjectName, String owner) throws IOException {
- removeCubeFromProjects(cubeName);
-
- return addCubeToProject(cubeName, newProjectName, owner);
- }
-
- public ProjectInstance updateTableToProject(String[] tables, String projectName) throws IOException {
- ProjectInstance projectInstance = getProject(projectName);
- for (int i = 0; i < tables.length; i++) {
- String token = tables[i].trim();
- int cut = token.indexOf('.');
- String tableName = cut >= 0 ? token.substring(cut + 1).trim() : token.trim();
- if (StringUtils.isNotEmpty(tableName)) {
- projectInstance.addTable(tableName);
- }
- }
-
- List<TableDesc> exposedTables = listExposedTables(projectName);
- for (TableDesc table : exposedTables) {
- projectInstance.addTable(table.getName());
- }
-
- saveResource(projectInstance);
- return projectInstance;
- }
-
-
- public void removeCubeFromProjects(String cubeName) throws IOException {
- for (ProjectInstance projectInstance : findProjects(cubeName)) {
- projectInstance.removeCube(cubeName);
-
- saveResource(projectInstance);
- }
- }
-
- public List<TableDesc> listExposedTables(String project) {
- project = ProjectInstance.getNormalizedProjectName(project);
- List<TableDesc> tables = Lists.newArrayList();
-
- for (ProjectTable table : projectTables.get(project)) {
- TableDesc tableDesc = getMetadataManager().getTableDesc(table.getName());
- if (tableDesc != null) {
- tables.add(tableDesc);
- }
- }
-
- return tables;
- }
-
-
- public List<TableDesc> listDefinedTablesInProject(String project) throws IOException {
- if(null==project){
- return Collections.emptyList();
- }
- project = ProjectInstance.getNormalizedProjectName(project);
- ProjectInstance projectInstance = getProject(project);
- int originTableCount = projectInstance.getTablesCount();
- //sync exposed table to project when list
- List<TableDesc> exposedTables = listExposedTables(project);
- for (TableDesc table : exposedTables) {
- projectInstance.addTable(table.getName());
- }
- //only save project json if new tables are sync in
- if (originTableCount < projectInstance.getTablesCount()) {
- saveResource(projectInstance);
- }
-
- List<TableDesc> tables = Lists.newArrayList();
- for (String table : projectInstance.getTables()) {
- TableDesc tableDesc = getMetadataManager().getTableDesc(table);
- if (tableDesc != null) {
- tables.add(tableDesc);
- }
- }
-
- return tables;
- }
-
- public List<ColumnDesc> listExposedColumns(String project, String table) {
- project = ProjectInstance.getNormalizedProjectName(project);
-
- MetadataManager metaMgr = getMetadataManager();
- TableDesc tableDesc = metaMgr.getTableDesc(table);
- List<ColumnDesc> columns = Lists.newArrayList();
-
- for (String column : this.getProjectTable(project, table).getColumns()) {
- columns.add(tableDesc.findColumnByName(column));
- }
-
- return columns;
- }
-
- public boolean isExposedTable(String project, String table) {
- project = ProjectInstance.getNormalizedProjectName(project);
-
- return projectTables.containsEntry(project, new ProjectTable(table));
- }
-
- public boolean isExposedColumn(String project, String table, String col) {
- project = ProjectInstance.getNormalizedProjectName(project);
-
- return getProjectTable(project, table).getColumns().contains(col);
- }
-
- public List<CubeInstance> listAllCubes(String project) {
- project = ProjectInstance.getNormalizedProjectName(project);
-
- HashSet<CubeInstance> ret = new HashSet<CubeInstance>();
-
- ProjectInstance projectInstance = getProject(project);
- if (projectInstance != null) {
- for (String cubeName : projectInstance.getCubes()) {
- CubeInstance cube = CubeManager.getInstance(config).getCube(cubeName);
- if (null != cube) {
- ret.add(cube);
- } else {
- logger.error("Failed to load cube " + cubeName);
- }
- }
- }
-
- return new ArrayList<CubeInstance>(ret);
- }
-
-
- public List<CubeInstance> getCubesByTable(String project, String tableName) {
- project = ProjectInstance.getNormalizedProjectName(project);
- tableName = tableName.toUpperCase();
- List<CubeInstance> cubes = new ArrayList<CubeInstance>();
-
- ProjectTable projectTable = getProjectTable(project, tableName);
- cubes.addAll(projectTable.getCubes());
-
- return cubes;
- }
-
- public List<CubeInstance> getOnlineCubesByFactTable(String project, String factTableName) {
- project = ProjectInstance.getNormalizedProjectName(project);
- factTableName = factTableName.toUpperCase();
- List<CubeInstance> cubes = new ArrayList<CubeInstance>();
- ProjectTable projectTable = this.getProjectTable(project, factTableName);
- for (CubeInstance cube : projectTable.getCubes()) {
- if (cube.getDescriptor().isFactTable(factTableName) && cube.isReady()) {
- cubes.add(cube);
- }
- }
-
- return cubes;
- }
-
- public List<MeasureDesc> listEffectiveRewriteMeasures(String project, String factTable) {
- factTable = factTable.toUpperCase();
-
- HashSet<CubeDesc> relatedDesc = new HashSet<CubeDesc>();
- for (CubeInstance cube : getProjectTable(project, factTable).getCubes()) {
- if (cube.isReady() == false)
- continue;
- if (cube.getDescriptor().isFactTable(factTable) == false)
- continue;
-
- relatedDesc.add(cube.getDescriptor());
- }
-
- List<MeasureDesc> result = Lists.newArrayList();
- for (CubeDesc desc : relatedDesc) {
- for (MeasureDesc m : desc.getMeasures()) {
- FunctionDesc func = m.getFunction();
- if (func.needRewrite())
- result.add(m);
- }
- }
-
- return result;
- }
-
- public void loadProjectCache(ProjectInstance project, boolean triggerUpdate) throws IOException {
- loadProject(project.getResourcePath(), triggerUpdate);
- loadTables(project.getResourcePath());
- }
-
- public void removeProjectCache(ProjectInstance project) {
- String projectName = ProjectInstance.getNormalizedProjectName(project.getName());
- if (projectMap.containsKey(projectName)) {
- projectMap.remove(projectName);
- projectTables.removeAll(projectName);
- }
- }
-
- private void mapTableToCube(ProjectInstance projectInstance, CubeInstance cubeInstance) {
- // schema sanity check
- CubeDesc cubeDesc = cubeInstance.getDescriptor();
- if (cubeDesc == null) {
- logger.warn("No CubeDesc found by name '" + cubeInstance.getDescName() + "'");
- return;
- }
-
- // table ==> cube mapping
- String factTable = cubeDesc.getFactTable();
- assert this.getMetadataManager().getTableDesc(factTable) != null;
-
- String project = ProjectInstance.getNormalizedProjectName(projectInstance.getName());
- ProjectTable factProjTable = this.getProjectTable(project, factTable, true);
- if (!factProjTable.getCubes().contains(cubeInstance)) {
- factProjTable.getCubes().add(cubeInstance);
- }
-
- for (DimensionDesc d : cubeDesc.getDimensions()) {
- String lookupTable = d.getTable();
- assert this.getMetadataManager().getTableDesc(lookupTable) != null;
-
- ProjectTable dimensionProjTable = this.getProjectTable(project, lookupTable);
- if (!dimensionProjTable.getCubes().contains(cubeInstance)) {
- dimensionProjTable.getCubes().add(cubeInstance);
- }
- }
- }
-
- private List<ProjectInstance> findProjects(String cubeName) {
- List<ProjectInstance> projects = new ArrayList<ProjectInstance>();
- for (ProjectInstance projectInstance : projectMap.values()) {
- if (projectInstance.containsCube(cubeName)) {
- projects.add(projectInstance);
- }
- }
-
- return projects;
- }
-
- private synchronized ProjectInstance loadProject(String path, boolean triggerUpdate) throws IOException {
- ResourceStore store = getStore();
-
- ProjectInstance projectInstance = store.getResource(path, ProjectInstance.class, PROJECT_SERIALIZER);
- projectInstance.init();
-
- if (StringUtils.isBlank(projectInstance.getName()))
- throw new IllegalStateException("Project name must not be blank");
-
- if (triggerUpdate) {
- projectMap.put(projectInstance.getName().toUpperCase(), projectInstance);
- } else {
- projectMap.putLocal(projectInstance.getName().toUpperCase(), projectInstance);
- }
-
- return projectInstance;
- }
-
- private synchronized void loadTables(String path) throws IOException {
- ResourceStore store = getStore();
-
- ProjectInstance projectInstance = store.getResource(path, ProjectInstance.class, PROJECT_SERIALIZER);
- projectInstance.init();
-
- String project = ProjectInstance.getNormalizedProjectName(projectInstance.getName());
- projectTables.removeAll(project);
-
- for (CubeInstance cubeInstance : this.listAllCubes(projectInstance.getName())) {
- markExposedTablesAndColumns(projectInstance.getName(), cubeInstance);
- mapTableToCube(projectInstance, cubeInstance);
- }
- }
-
- private void loadAllProjects() throws IOException {
- ResourceStore store = getStore();
- List<String> paths = store.collectResourceRecursively(ResourceStore.PROJECT_RESOURCE_ROOT, ".json");
-
- logger.debug("Loading Project from folder " + store.getReadableResourcePath(ResourceStore.PROJECT_RESOURCE_ROOT));
-
- for (String path : paths) {
- loadProject(path, false);
- loadTables(path);
- }
-
- logger.debug("Loaded " + paths.size() + " Project(s)");
- }
-
- private ProjectInstance addCubeToProject(String cubeName, String project, String user) throws IOException {
- String newProjectName = ProjectInstance.getNormalizedProjectName(project);
- ProjectInstance newProject = getProject(newProjectName);
- if (newProject == null) {
- newProject = this.createProject(newProjectName, user, "This is a project automatically added when adding cube " + cubeName);
- }
- newProject.addCube(cubeName);
- saveResource(newProject);
-
- return newProject;
- }
-
- private void saveResource(ProjectInstance proj) throws IOException {
- ResourceStore store = getStore();
- store.putResource(proj.getResourcePath(), proj, PROJECT_SERIALIZER);
- afterProjectUpdated(proj);
- }
-
- private void deleteResource(ProjectInstance proj) throws IOException {
- ResourceStore store = getStore();
- store.deleteResource(proj.getResourcePath());
- this.afterProjectDropped(proj);
- }
-
- private void afterProjectUpdated(ProjectInstance updatedProject) {
- try {
- this.loadProjectCache(updatedProject, true);
- } catch (IOException e) {
- logger.error(e.getLocalizedMessage(), e);
- }
- }
-
- private void afterProjectDropped(ProjectInstance droppedProject) {
- this.removeProjectCache(droppedProject);
- }
-
- // sync on update
- private void markExposedTablesAndColumns(String projectName, CubeInstance cubeInstance) {
- if (!cubeInstance.isReady())
- return;
-
- CubeDesc cubeDesc = cubeInstance.getDescriptor();
- String factTable = cubeDesc.getFactTable();
- for (DimensionDesc dim : cubeDesc.getDimensions()) {
- String lookupTable = dim.getTable();
- JoinDesc join = dim.getJoin();
- if (join == null)
- continue; // for dimensions on fact table, there's no join
-
- if (join.getForeignKeyColumns() == null) {
- throw new IllegalStateException("Null FK for " + join);
- }
- for (TblColRef fkCol : join.getForeignKeyColumns()) {
- markExposedTableAndColumn(projectName, factTable, fkCol.getName(), dim);
- }
- if (join.getPrimaryKeyColumns() == null) {
- throw new IllegalStateException("Null PK for " + join);
- }
- for (TblColRef pkCol : join.getPrimaryKeyColumns()) {
- markExposedTableAndColumn(projectName, lookupTable, pkCol.getName(), dim);
- }
- }
- for (TblColRef col : cubeDesc.listAllColumns()) {
- markExposedTableAndColumn(projectName, col.getTable(), col.getName(), col);
- }
- }
-
- private void markExposedTableAndColumn(String project, String table, String column, Object refObj) {
- project = ProjectInstance.getNormalizedProjectName(project);
- TableDesc t = this.getMetadataManager().getTableDesc(table);
- if (t == null)
- throw new IllegalStateException("No SourceTable found by name '" + table + "', ref by " + refObj);
- table = t.getName(); // ensures upper case
-
- ProjectTable projTable = getProjectTable(project, table, true);
-
- ColumnDesc srcCol = t.findColumnByName(column);
- if (srcCol == null)
- throw new IllegalStateException("No SourceColumn found by name '" + table + "/" + column + "', ref by " + refObj);
-
- if (!projTable.getColumns().contains(srcCol.getName())) {
- projTable.getColumns().add(srcCol.getName());
- }
- }
-
- private ProjectTable getProjectTable(String project, final String table) {
- return getProjectTable(project, table, false);
- }
-
- private ProjectTable getProjectTable(String project, final String table, boolean autoCreate) {
- ProjectTable projectTable = null;
- project = ProjectInstance.getNormalizedProjectName(project);
-
- if (this.projectTables.containsEntry(project, new ProjectTable(table))) {
- Iterator<ProjectTable> projsIter = this.projectTables.get(project).iterator();
- while (projsIter.hasNext()) {
- ProjectTable oneTable = projsIter.next();
- if (oneTable.getName().equalsIgnoreCase(table)) {
- projectTable = oneTable;
- break;
- }
- }
- } else {
- projectTable = new ProjectTable(table);
-
- if (autoCreate) {
- this.projectTables.put(project, projectTable);
- }
- }
-
- return projectTable;
- }
-
- private ResourceStore getStore() {
- return ResourceStore.getStore(this.config);
- }
-
- private MetadataManager getMetadataManager() {
- return MetadataManager.getInstance(config);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/a4fd4268/cube/src/main/java/com/kylinolap/cube/project/ProjectStatusEnum.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/com/kylinolap/cube/project/ProjectStatusEnum.java b/cube/src/main/java/com/kylinolap/cube/project/ProjectStatusEnum.java
deleted file mode 100644
index 0c582a7..0000000
--- a/cube/src/main/java/com/kylinolap/cube/project/ProjectStatusEnum.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2013-2014 eBay Software Foundation
- *
- * Licensed 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 com.kylinolap.cube.project;
-
-public enum ProjectStatusEnum {
-
- DISABLED, ENABLED
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/a4fd4268/cube/src/main/java/com/kylinolap/cube/project/ProjectTable.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/com/kylinolap/cube/project/ProjectTable.java b/cube/src/main/java/com/kylinolap/cube/project/ProjectTable.java
deleted file mode 100644
index 0344010..0000000
--- a/cube/src/main/java/com/kylinolap/cube/project/ProjectTable.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2013-2014 eBay Software Foundation
- *
- * Licensed 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 com.kylinolap.cube.project;
-
-import com.google.common.collect.HashMultiset;
-import com.google.common.collect.Multiset;
-import com.kylinolap.cube.CubeInstance;
-
-/**
- * @author xduo
- *
- */
-public class ProjectTable {
-
- private final String name;
-
- private Multiset<String> columns = HashMultiset.create();
-
- private Multiset<CubeInstance> cubes = HashMultiset.create();
-
- /**
- * @param name
- */
- public ProjectTable(String name) {
- super();
- this.name = name.toUpperCase();
- }
-
- public String getName() {
- return name;
- }
-
- public Multiset<String> getColumns() {
- return columns;
- }
-
- public void setColumns(Multiset<String> columns) {
- this.columns = columns;
- }
-
- public Multiset<CubeInstance> getCubes() {
- return cubes;
- }
-
- public void setCubes(Multiset<CubeInstance> cubes) {
- this.cubes = cubes;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.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;
- ProjectTable other = (ProjectTable) obj;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "ProjectTable [name=" + name + ", columns=" + columns + "]";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/a4fd4268/cube/src/test/java/com/kylinolap/cube/CubeManagerCacheTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/com/kylinolap/cube/CubeManagerCacheTest.java b/cube/src/test/java/com/kylinolap/cube/CubeManagerCacheTest.java
deleted file mode 100644
index 372cc17..0000000
--- a/cube/src/test/java/com/kylinolap/cube/CubeManagerCacheTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2013-2014 eBay Software Foundation
- *
- * Licensed 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 com.kylinolap.cube;
-
-import static org.junit.Assert.*;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.kylinolap.common.persistence.ResourceStore;
-import com.kylinolap.common.util.LocalFileMetadataTestCase;
-import com.kylinolap.cube.project.ProjectManager;
-import com.kylinolap.metadata.MetadataManager;
-import com.kylinolap.metadata.model.cube.CubeDesc;
-
-/**
- * @author yangli9
- *
- */
-public class CubeManagerCacheTest extends LocalFileMetadataTestCase {
-
- private CubeManager cubeManager;
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- MetadataManager.removeInstance(this.getTestConfig());
- CubeManager.removeInstance(this.getTestConfig());
- ProjectManager.removeInstance(this.getTestConfig());
- cubeManager = CubeManager.getInstance(this.getTestConfig());
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test
- public void testReloadCache() throws Exception {
- ResourceStore store = getStore();
-
- // clean legacy in case last run failed
- store.deleteResource("/cube/a_whole_new_cube.json");
- MetadataManager metaMgr = getMetadataManager();
- CubeDesc desc = metaMgr.getCubeDesc("test_kylin_cube_with_slr_desc");
- cubeManager.createCube("a_whole_new_cube", "default", desc, null);
-
- CubeInstance createdCube = cubeManager.getCube("a_whole_new_cube");
- assertEquals(0, createdCube.getSegments().size());
- assertEquals(CubeStatusEnum.DISABLED, createdCube.getStatus());
- createdCube.setStatus(CubeStatusEnum.DESCBROKEN);
-
- cubeManager.updateCube(createdCube);
- assertEquals(CubeStatusEnum.DESCBROKEN, cubeManager.getCube("a_whole_new_cube").getStatus());
- }
-
- private MetadataManager getMetadataManager() {
- return MetadataManager.getInstance(getTestConfig());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/a4fd4268/cube/src/test/java/com/kylinolap/cube/CubeManagerTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/com/kylinolap/cube/CubeManagerTest.java b/cube/src/test/java/com/kylinolap/cube/CubeManagerTest.java
deleted file mode 100644
index 82d2c0e..0000000
--- a/cube/src/test/java/com/kylinolap/cube/CubeManagerTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2013-2014 eBay Software Foundation
- *
- * Licensed 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 com.kylinolap.cube;
-
-import static org.junit.Assert.*;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.kylinolap.common.persistence.ResourceStore;
-import com.kylinolap.common.util.JsonUtil;
-import com.kylinolap.common.util.LocalFileMetadataTestCase;
-import com.kylinolap.cube.project.ProjectInstance;
-import com.kylinolap.cube.project.ProjectManager;
-import com.kylinolap.metadata.MetadataManager;
-import com.kylinolap.metadata.model.cube.CubeDesc;
-
-/**
- * @author yangli9
- */
-public class CubeManagerTest extends LocalFileMetadataTestCase {
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- MetadataManager.removeInstance(this.getTestConfig());
- CubeManager.removeInstance(this.getTestConfig());
- ProjectManager.removeInstance(this.getTestConfig());
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test
- public void testBasics() throws Exception {
- CubeInstance cube = CubeManager.getInstance(this.getTestConfig()).getCube("test_kylin_cube_without_slr_ready");
- CubeDesc desc = cube.getDescriptor();
- System.out.println(JsonUtil.writeValueAsIndentString(desc));
-
- String signature = desc.calculateSignature();
- desc.getCubePartitionDesc().setPartitionDateColumn("test_column");
- assertTrue(!signature.equals(desc.calculateSignature()));
- }
-
- @Test
- public void testCreateAndDrop() throws Exception {
-
- ResourceStore store = getStore();
-
- // clean legacy in case last run failed
- store.deleteResource("/cube/a_whole_new_cube.json");
-
- MetadataManager metaMgr = getMetadataManager();
- CubeDesc desc = metaMgr.getCubeDesc("test_kylin_cube_with_slr_desc");
- CubeInstance createdCube = CubeManager.getInstance(this.getTestConfig()).createCube("a_whole_new_cube", ProjectInstance.DEFAULT_PROJECT_NAME, desc, null);
- assertTrue(createdCube == CubeManager.getInstance(this.getTestConfig()).getCube("a_whole_new_cube"));
-
- assertTrue(ProjectManager.getInstance(getTestConfig()).listAllCubes(ProjectInstance.DEFAULT_PROJECT_NAME).contains(createdCube));
-
- CubeInstance droppedCube = CubeManager.getInstance(this.getTestConfig()).dropCube("a_whole_new_cube", true);
- assertTrue(createdCube == droppedCube);
-
- assertTrue(!ProjectManager.getInstance(getTestConfig()).listAllCubes(ProjectInstance.DEFAULT_PROJECT_NAME).contains(droppedCube));
-
- assertNull(CubeManager.getInstance(this.getTestConfig()).getCube("a_whole_new_cube"));
- }
-
- private MetadataManager getMetadataManager() {
- return MetadataManager.getInstance(getTestConfig());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/a4fd4268/cube/src/test/java/com/kylinolap/cube/CubeSizeEstimationCLITest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/com/kylinolap/cube/CubeSizeEstimationCLITest.java b/cube/src/test/java/com/kylinolap/cube/CubeSizeEstimationCLITest.java
deleted file mode 100644
index 0f0a4b2..0000000
--- a/cube/src/test/java/com/kylinolap/cube/CubeSizeEstimationCLITest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.kylinolap.cube;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.kylinolap.common.util.LocalFileMetadataTestCase;
-import com.kylinolap.cube.estimation.CubeSizeEstimationCLI;
-import com.kylinolap.metadata.MetadataManager;
-import com.kylinolap.metadata.model.cube.CubeDesc;
-
-/**
- * Created by honma on 9/1/14.
- */
-public class CubeSizeEstimationCLITest extends LocalFileMetadataTestCase {
-
- String cubeName = "test_kylin_cube_with_slr_ready";
- long[] cardinality;
- CubeDesc cubeDesc;
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- MetadataManager.removeInstance(this.getTestConfig());
-
- String cubeName = "test_kylin_cube_with_slr_ready";
- CubeManager cubeManager = CubeManager.getInstance(getTestConfig());
- CubeInstance cubeInstance = cubeManager.getCube(cubeName);
- cubeDesc = cubeInstance.getDescriptor();
- cardinality = new long[] { 100, 100, 100, 10000, 1000, 100, 100, 100, 100 };
-
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test
- public void test() {
- long[] x = new long[] { 5, 8, 5, 115, 122, 127, 137, 236, 101 };
- CubeSizeEstimationCLI.estimatedCubeSize(cubeName, x);
- }
-
- @Test
- public void baseCuboidTest() {
- long cuboidID = getCuboidID(0, 1, 2, 3, 4, 5, 6, 7, 8);
- long size = CubeSizeEstimationCLI.estimateCuboidSpace(cuboidID, cardinality, cubeDesc);
-
- assert size == (10000000000000000L * (32 + 39));
- }
-
- @Test
- public void cuboidTest1() {
- long cuboidID = getCuboidID(0, 1, 2, 4, 5, 6, 7, 8);
- long size = CubeSizeEstimationCLI.estimateCuboidSpace(cuboidID, cardinality, cubeDesc);
-
- assert size == (1000000000000000L * (32 + 37));
- }
-
- @Test
- public void cuboidTest2() {
-
- long cuboidID = getCuboidID(0);
- long size = CubeSizeEstimationCLI.estimateCuboidSpace(cuboidID, cardinality, cubeDesc);
-
- assert size == (100L * (1 + 32));
- }
-
- @Test
- public void cuboidTest3() {
- long cuboidID = getCuboidID(4, 5);
- long size = CubeSizeEstimationCLI.estimateCuboidSpace(cuboidID, cardinality, cubeDesc);
-
- assert size == (1000L * (3 + 32));
- }
-
- @Test
- public void cuboidTest4() {
- long cuboidID = getCuboidID(4, 5, 6);
- long size = CubeSizeEstimationCLI.estimateCuboidSpace(cuboidID, cardinality, cubeDesc);
-
- assert size == (100000L * (4 + 32));
- }
-
- private long getCuboidID(int... bitIndice) {
- long ret = 0;
- long mask = 1L;
- for (int index : bitIndice) {
- ret |= mask << index;
- }
- return ret;
- }
-}