Java Code Examples for org.apache.kylin.metadata.model.DataModelDesc#setName()
The following examples show how to use
org.apache.kylin.metadata.model.DataModelDesc#setName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelCreator.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
public static DataModelDesc generateKylinModel(String owner, String tableName, List<String> dimensions, List<String> measures, PartitionDesc partitionDesc) { ModelDimensionDesc modelDimensionDesc = new ModelDimensionDesc(); modelDimensionDesc.setTable(tableName); modelDimensionDesc.setColumns(dimensions.toArray(new String[dimensions.size()])); DataModelDesc kylinModel = new DataModelDesc(); kylinModel.setName(tableName.replace('.', '_')); kylinModel.setOwner(owner); kylinModel.setDescription(""); kylinModel.setLastModified(0L); kylinModel.setRootFactTableName(tableName); kylinModel.setJoinTables(new JoinTableDesc[0]); kylinModel.setDimensions(Lists.newArrayList(modelDimensionDesc)); kylinModel.setMetrics(measures.toArray(new String[measures.size()])); kylinModel.setFilterCondition(""); kylinModel.setPartitionDesc(partitionDesc); kylinModel.setCapacity(DataModelDesc.RealizationCapacity.SMALL); kylinModel.updateRandomUuid(); return kylinModel; }
Example 2
Source File: ModelCreator.java From kylin with Apache License 2.0 | 6 votes |
public static DataModelDesc generateKylinModel(String owner, String tableName, List<String> dimensions, List<String> measures, PartitionDesc partitionDesc) { ModelDimensionDesc modelDimensionDesc = new ModelDimensionDesc(); modelDimensionDesc.setTable(tableName); modelDimensionDesc.setColumns(dimensions.toArray(new String[dimensions.size()])); DataModelDesc kylinModel = new DataModelDesc(); kylinModel.setName(tableName.replace('.', '_')); kylinModel.setOwner(owner); kylinModel.setDescription(""); kylinModel.setLastModified(0L); kylinModel.setRootFactTableName(tableName); kylinModel.setJoinTables(new JoinTableDesc[0]); kylinModel.setDimensions(Lists.newArrayList(modelDimensionDesc)); kylinModel.setMetrics(measures.toArray(new String[measures.size()])); kylinModel.setFilterCondition(""); kylinModel.setPartitionDesc(partitionDesc); kylinModel.setCapacity(DataModelDesc.RealizationCapacity.SMALL); kylinModel.updateRandomUuid(); return kylinModel; }
Example 3
Source File: CubeDescUpgrader.java From Kylin with Apache License 2.0 | 5 votes |
private DataModelDesc extractDataModel(CubeDesc oldModel, org.apache.kylin.cube.model.CubeDesc newModel) { DataModelDesc dm = new DataModelDesc(); dm.setUuid(UUID.randomUUID().toString()); String factTable = oldModel.getFactTable(); dm.setName(oldModel.getName()); dm.setFactTable(getMetadataManager().appendDBName(factTable)); newModel.setModelName(dm.getName()); List<org.apache.kylin.cube.model.v1.DimensionDesc> oldDimensions = oldModel.getDimensions(); List<LookupDesc> lookups = Lists.newArrayList(); for (org.apache.kylin.cube.model.v1.DimensionDesc dim : oldDimensions) { JoinDesc join = dim.getJoin(); if (join != null && !StringUtils.isEmpty(join.getType()) && join.getForeignKey() != null && join.getForeignKey().length > 0) { LookupDesc lookup = new LookupDesc(); lookup.setJoin(join); String table = dim.getTable(); lookup.setTable(getMetadataManager().appendDBName(table)); lookups.add(lookup); } } dm.setLookups(lookups.toArray(new LookupDesc[lookups.size()])); dm.setFilterCondition(oldModel.getFilterCondition()); updatePartitionDesc(oldModel, dm); if (oldModel.getCapacity() == CubeDesc.CubeCapacity.SMALL) { dm.setCapacity(DataModelDesc.RealizationCapacity.SMALL); } else if (oldModel.getCapacity() == CubeDesc.CubeCapacity.MEDIUM) { dm.setCapacity(DataModelDesc.RealizationCapacity.MEDIUM); } else if (oldModel.getCapacity() == CubeDesc.CubeCapacity.LARGE) { dm.setCapacity(DataModelDesc.RealizationCapacity.LARGE); } return dm; }
Example 4
Source File: CacheServiceTest.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@Test public void testMetaCRUD() throws Exception { final TableMetadataManager tableMgr = TableMetadataManager.getInstance(configA); final TableMetadataManager tableMgrB = TableMetadataManager.getInstance(configB); final DataModelManager modelMgr = DataModelManager.getInstance(configA); final DataModelManager modelMgrB = DataModelManager.getInstance(configB); final Broadcaster broadcaster = Broadcaster.getInstance(configA); broadcaster.getCounterAndClear(); TableDesc tableDesc = createTestTableDesc(); assertTrue(tableMgr.getTableDesc(tableDesc.getIdentity(), "default") == null); assertTrue(tableMgrB.getTableDesc(tableDesc.getIdentity(), "default") == null); tableMgr.saveSourceTable(tableDesc, "default"); //only one for table insert assertEquals(1, broadcaster.getCounterAndClear()); waitForCounterAndClear(1); assertNotNull(tableMgr.getTableDesc(tableDesc.getIdentity(), "default")); assertNotNull(tableMgrB.getTableDesc(tableDesc.getIdentity(), "default")); final String dataModelName = "test_data_model"; DataModelDesc dataModelDesc = modelMgr.getDataModelDesc("test_kylin_left_join_model_desc"); dataModelDesc.setName(dataModelName); dataModelDesc.setLastModified(0); assertTrue(modelMgr.getDataModelDesc(dataModelName) == null); assertTrue(modelMgrB.getDataModelDesc(dataModelName) == null); dataModelDesc.setName(dataModelName); modelMgr.createDataModelDesc(dataModelDesc, "default", "ADMIN"); //one for data model creation, one for project meta update assertEquals(2, broadcaster.getCounterAndClear()); waitForCounterAndClear(2); assertEquals(dataModelDesc.getName(), modelMgrB.getDataModelDesc(dataModelName).getName()); final JoinTableDesc[] lookups = dataModelDesc.getJoinTables(); assertTrue(lookups.length > 0); modelMgr.updateDataModelDesc(dataModelDesc); //only one for data model update assertEquals(1, broadcaster.getCounterAndClear()); waitForCounterAndClear(1); assertEquals(dataModelDesc.getJoinTables().length, modelMgrB.getDataModelDesc(dataModelName).getJoinTables().length); }
Example 5
Source File: ModelController.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@RequestMapping(value = "/{modelName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" }) @ResponseBody public ModelRequest cloneModel(@PathVariable String modelName, @RequestBody ModelRequest modelRequest) { String project = StringUtils.trimToNull(modelRequest.getProject()); DataModelManager metaManager = DataModelManager.getInstance(KylinConfig.getInstanceFromEnv()); DataModelDesc modelDesc = metaManager.getDataModelDesc(modelName); String newModelName = modelRequest.getModelName(); if (null == project) { throw new BadRequestException("Project name should not be empty."); } if (modelDesc == null || StringUtils.isEmpty(modelName)) { throw new NotFoundException("Model does not exist."); } if (!project.equals(modelDesc.getProject())) { throw new BadRequestException("Cloning model across projects is not supported."); } if (StringUtils.isEmpty(newModelName)) { throw new BadRequestException("New model name should not be empty."); } if (!ValidateUtil.isAlphanumericUnderscore(newModelName)) { throw new BadRequestException(String.format(Locale.ROOT, "Invalid model name %s, only letters, numbers and underscore supported.", newModelName)); } DataModelDesc newModelDesc = DataModelDesc.getCopyOf(modelDesc); newModelDesc.setProjectName(project); newModelDesc.setName(newModelName); try { newModelDesc = modelService.createModelDesc(project, newModelDesc); //reload avoid shallow metaManager.reloadDataModel(newModelName); } catch (IOException e) { throw new InternalErrorException("failed to clone DataModelDesc", e); } modelRequest.setUuid(newModelDesc.getUuid()); modelRequest.setSuccessful(true); return modelRequest; }
Example 6
Source File: CacheServiceTest.java From kylin with Apache License 2.0 | 4 votes |
@Test public void testMetaCRUD() throws Exception { final TableMetadataManager tableMgr = TableMetadataManager.getInstance(configA); final TableMetadataManager tableMgrB = TableMetadataManager.getInstance(configB); final DataModelManager modelMgr = DataModelManager.getInstance(configA); final DataModelManager modelMgrB = DataModelManager.getInstance(configB); final Broadcaster broadcaster = Broadcaster.getInstance(configA); broadcaster.getCounterAndClear(); TableDesc tableDesc = createTestTableDesc(); assertTrue(tableMgr.getTableDesc(tableDesc.getIdentity(), "default") == null); assertTrue(tableMgrB.getTableDesc(tableDesc.getIdentity(), "default") == null); tableMgr.saveSourceTable(tableDesc, "default"); //only one for table insert assertEquals(1, broadcaster.getCounterAndClear()); waitForCounterAndClear(1); assertNotNull(tableMgr.getTableDesc(tableDesc.getIdentity(), "default")); assertNotNull(tableMgrB.getTableDesc(tableDesc.getIdentity(), "default")); final String dataModelName = "test_data_model"; DataModelDesc dataModelDesc = modelMgr.getDataModelDesc("test_kylin_left_join_model_desc"); dataModelDesc.setName(dataModelName); dataModelDesc.setLastModified(0); assertTrue(modelMgr.getDataModelDesc(dataModelName) == null); assertTrue(modelMgrB.getDataModelDesc(dataModelName) == null); dataModelDesc.setName(dataModelName); modelMgr.createDataModelDesc(dataModelDesc, "default", "ADMIN"); //one for data model creation, one for project meta update assertEquals(2, broadcaster.getCounterAndClear()); waitForCounterAndClear(2); assertEquals(dataModelDesc.getName(), modelMgrB.getDataModelDesc(dataModelName).getName()); final JoinTableDesc[] lookups = dataModelDesc.getJoinTables(); assertTrue(lookups.length > 0); modelMgr.updateDataModelDesc(dataModelDesc); //only one for data model update assertEquals(1, broadcaster.getCounterAndClear()); waitForCounterAndClear(1); assertEquals(dataModelDesc.getJoinTables().length, modelMgrB.getDataModelDesc(dataModelName).getJoinTables().length); }
Example 7
Source File: ModelController.java From kylin with Apache License 2.0 | 4 votes |
@RequestMapping(value = "/{modelName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" }) @ResponseBody public ModelRequest cloneModel(@PathVariable String modelName, @RequestBody ModelRequest modelRequest) { String project = StringUtils.trimToNull(modelRequest.getProject()); DataModelManager metaManager = DataModelManager.getInstance(KylinConfig.getInstanceFromEnv()); DataModelDesc modelDesc = metaManager.getDataModelDesc(modelName); String newModelName = modelRequest.getModelName(); if (null == project) { throw new BadRequestException("Project name should not be empty."); } if (modelDesc == null || StringUtils.isEmpty(modelName)) { throw new NotFoundException("Model does not exist."); } if (!project.equals(modelDesc.getProject())) { throw new BadRequestException("Cloning model across projects is not supported."); } if (StringUtils.isEmpty(newModelName)) { throw new BadRequestException("New model name should not be empty."); } if (!ValidateUtil.isAlphanumericUnderscore(newModelName)) { throw new BadRequestException(String.format(Locale.ROOT, "Invalid model name %s, only letters, numbers and underscore supported.", newModelName)); } DataModelDesc newModelDesc = DataModelDesc.getCopyOf(modelDesc); newModelDesc.setProjectName(project); newModelDesc.setName(newModelName); try { newModelDesc = modelService.createModelDesc(project, newModelDesc); //reload avoid shallow metaManager.reloadDataModel(newModelName); } catch (IOException e) { throw new InternalErrorException("failed to clone DataModelDesc", e); } modelRequest.setUuid(newModelDesc.getUuid()); modelRequest.setSuccessful(true); return modelRequest; }
Example 8
Source File: CacheServiceTest.java From Kylin with Apache License 2.0 | 4 votes |
@Test public void testMetaCRUD() throws Exception { final MetadataManager metadataManager = MetadataManager.getInstance(configA); final MetadataManager metadataManagerB = MetadataManager.getInstance(configB); final Broadcaster broadcaster = Broadcaster.getInstance(); broadcaster.getCounterAndClear(); TableDesc tableDesc = createTestTableDesc(); assertTrue(metadataManager.getTableDesc(tableDesc.getIdentity()) == null); assertTrue(metadataManagerB.getTableDesc(tableDesc.getIdentity()) == null); metadataManager.saveSourceTable(tableDesc); //only one for table insert assertEquals(1, broadcaster.getCounterAndClear()); waitForCounterAndClear(1); assertNotNull(metadataManager.getTableDesc(tableDesc.getIdentity())); assertNotNull(metadataManagerB.getTableDesc(tableDesc.getIdentity())); final String dataModelName = "test_data_model"; DataModelDesc dataModelDesc = metadataManager.getDataModelDesc("test_kylin_ii_model_desc"); dataModelDesc.setName(dataModelName); dataModelDesc.setLastModified(0); assertTrue(metadataManager.getDataModelDesc(dataModelName) == null); assertTrue(metadataManagerB.getDataModelDesc(dataModelName) == null); dataModelDesc.setName(dataModelName); metadataManager.createDataModelDesc(dataModelDesc); //only one for data model update assertEquals(1, broadcaster.getCounterAndClear()); waitForCounterAndClear(1); assertEquals(dataModelDesc.getName(), metadataManagerB.getDataModelDesc(dataModelName).getName()); final LookupDesc[] lookups = dataModelDesc.getLookups(); assertTrue(lookups.length > 0); dataModelDesc.setLookups(new LookupDesc[]{lookups[0]}); metadataManager.updateDataModelDesc(dataModelDesc); //only one for data model update assertEquals(1, broadcaster.getCounterAndClear()); waitForCounterAndClear(1); assertEquals(dataModelDesc.getLookups().length, metadataManagerB.getDataModelDesc(dataModelName).getLookups().length); }