本文整理汇总了Java中org.pentaho.metadata.model.LogicalModel.setId方法的典型用法代码示例。如果您正苦于以下问题:Java LogicalModel.setId方法的具体用法?Java LogicalModel.setId怎么用?Java LogicalModel.setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pentaho.metadata.model.LogicalModel
的用法示例。
在下文中一共展示了LogicalModel.setId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFromXML
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testFromXML() throws Exception {
Domain domain = TestHelper.getBasicDomain();
LogicalModel model = TestHelper.buildDefaultModel();
domain.addLogicalModel( model );
model.setId( "MODEL2" );
Query query = new Query( domain, model );
String xml = helper.toXML( query );
try {
query = helper.fromXML( metadataDomainRepository, xml );
fail();
} catch ( PentahoMetadataException e ) {
// expected
}
}
示例2: init
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Before
public void init() throws Exception {
helper = new QueryXmlHelper();
Domain domain = TestHelper.getBasicDomain();
LogicalModel model = TestHelper.buildDefaultModel();
domain.addLogicalModel( model );
model.setId( "MODEL1" );
query = new Query( domain, model );
LogicalColumn column = new LogicalColumn();
column.setId( "LC_Test_Column1" );
LogicalColumn column2 = new LogicalColumn();
column2.setId( "LC_Test_Column2" );
Category category = new Category();
category.getLogicalColumns().add( column );
query.getLogicalModel().getCategories().add( category );
LogicalTable lt = new LogicalTable();
lt.getLogicalColumns().add( column );
lt.getLogicalColumns().add( column2 );
query.getLogicalModel().getLogicalTables().add( lt );
documentBuilderFactory = DocumentBuilderFactory.newInstance();
db = documentBuilderFactory.newDocumentBuilder();
doc = db.newDocument();
metadataDomainRepository = new InMemoryMetadataDomainRepository();
metadataDomainRepository.storeDomain( domain, true );
}
示例3: generatePhysicalMetadataModel
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
public Domain generatePhysicalMetadataModel() throws KettleException {
// First do some checking and lookups...
//
String targetDatabaseName = ConceptUtil.getString(logicalDomain, DefaultIDs.DOMAIN_TARGET_DATABASE);
if (Const.isEmpty(targetDatabaseName)) {
throw new KettleException("Please specify a target database!");
}
DatabaseMeta targetDatabaseMeta = DatabaseMeta.findDatabase(databases, targetDatabaseName);
if (targetDatabaseMeta==null) {
throw new KettleException("Target database with name '"+targetDatabaseName+"' can't be found!");
}
// Now start creation of a new domain with physical underpinning.
//
Domain domain = new Domain();
// Copy the domain information...
//
domain.setId( createId("DOMAIN", null, domain) );
domain.setName(logicalDomain.getName());
domain.setDescription(logicalDomain.getDescription());
// Now copy all the models...
//
for (LogicalModel logicalModel : logicalDomain.getLogicalModels()) {
// Copy model information...
//
LogicalModel model = new LogicalModel();
model.setId( createId("MODEL", domain, model));
model.setName(logicalModel.getName());
model.setDescription(logicalModel.getDescription());
// Create a physical model...
//
SqlPhysicalModel sqlModel = new SqlPhysicalModel();
sqlModel.setDatasource(createSqlDataSource(targetDatabaseMeta));
model.setPhysicalModel(sqlModel);
for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
LogicalTable table = new LogicalTable();
table.setId( createId("LOGICAL_TABLE", logicalModel, logicalTable) );
table.setName(logicalTable.getName());
table.setDescription(logicalTable.getDescription());
String targetTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
SqlPhysicalTable sqlTable = new SqlPhysicalTable(sqlModel);
table.setPhysicalTable(sqlTable);
// Copy name & description from physical level...
//
sqlTable.setId( createId("PHYSICAL_TABLE", logicalModel, logicalTable));
sqlTable.setName(logicalTable.getName());
sqlTable.setDescription(logicalTable.getDescription());
sqlTable.setTableType(ConceptUtil.getTableType(logicalTable));
sqlTable.setTargetSchema(targetDatabaseMeta.getPreferredSchemaName());
sqlTable.setTargetTable(targetTable);
}
}
return domain;
}
示例4: generateDomain
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
public Domain generateDomain( final ImportStrategy importStrategy ) throws PentahoMetadataException {
Domain domain = new Domain();
domain.setId( modelName );
List<LocaleType> locales = new ArrayList<LocaleType>();
locales.add( new LocaleType( "en_US", "English (US)" ) ); //$NON-NLS-1$ //$NON-NLS-2$
domain.setLocales( locales );
SqlPhysicalModel physicalModel = new SqlPhysicalModel();
physicalModel.setId( databaseMeta.getName() );
physicalModel.setDatasource( ThinModelConverter.convertFromLegacy( databaseMeta ) );
Database database = database();
try {
// Add the database connection to the empty schema...
//
domain.addPhysicalModel( physicalModel );
// Also add a model with the same name as the model name...
//
String bmID = Util.getLogicalModelIdPrefix() + "_" + modelName.replaceAll( " ", "_" ).toUpperCase(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
LogicalModel logicalModel = new LogicalModel();
logicalModel.setId( bmID );
domain.addLogicalModel( logicalModel );
// Connect to the database...
//
database.connect();
// clear the cache
DBCache.getInstance().clear( databaseMeta.getName() );
for ( int i = 0; i < tableNames.length; i++ ) {
SchemaTable schemaTable = tableNames[i];
// Import the specified tables and turn them into PhysicalTable
// objects...
//
SqlPhysicalTable physicalTable =
PhysicalTableImporter.importTableDefinition( database, schemaTable.getSchemaName(), schemaTable
.getTableName(), locale, importStrategy );
physicalModel.addPhysicalTable( physicalTable );
// At the same time, we will create a business table and add that to the
// business model...
//
LogicalTable businessTable = createBusinessTable( physicalTable, locale );
logicalModel.addLogicalTable( businessTable );
}
} catch ( Exception e ) {
// For the unexpected stuff, just throw the exception upstairs.
//
throw new PentahoMetadataException( e );
} finally {
// Make sure to close the connection
//
database.disconnect();
}
return domain;
}
示例5: createModel
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
private LogicalModel createModel() {
final LogicalModel model = new LogicalModel();
model.setId( "model_01" );
Category mainCat = new Category();
mainCat.setId( "cat_01" );
model.getCategories().add( mainCat );
final LogicalTable bt1 = new LogicalTable();
bt1.setId( "bt1" ); //$NON-NLS-1$
bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "pt1" ); //$NON-NLS-1$
final LogicalColumn bc1 = new LogicalColumn();
bc1.setId( "bc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "pc1" ); //$NON-NLS-1$
bc1.setLogicalTable( bt1 );
bt1.addLogicalColumn( bc1 );
bt1.setProperty( SqlPhysicalTable.RELATIVE_SIZE, 1 );
mainCat.addLogicalColumn( bc1 );
model.getLogicalTables().add( bt1 );
final LogicalTable bt2 = new LogicalTable();
bt2.setId( "bt2" ); //$NON-NLS-1$
bt2.setProperty( SqlPhysicalTable.TARGET_TABLE, "pt2" ); //$NON-NLS-1$
final LogicalColumn bc2 = new LogicalColumn();
bc2.setId( "bc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "pc2" ); //$NON-NLS-1$
bc2.setLogicalTable( bt2 );
bt2.addLogicalColumn( bc2 );
mainCat.addLogicalColumn( bc2 );
model.getLogicalTables().add( bt2 );
final LogicalColumn bce2 = new LogicalColumn();
bce2.setId( "bce2" ); //$NON-NLS-1$
bce2.setProperty( SqlPhysicalColumn.TARGET_COLUMN_TYPE, TargetColumnType.OPEN_FORMULA );
bce2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "[bt2.bc2] * [bt1.bc1]" ); //$NON-NLS-1$
bce2.setLogicalTable( bt2 );
bt2.addLogicalColumn( bce2 );
mainCat.addLogicalColumn( bce2 );
final LogicalRelationship rl1 = new LogicalRelationship();
rl1.setFromTable( bt1 );
rl1.setFromColumn( bc1 );
rl1.setToTable( bt2 );
rl1.setToColumn( bc2 );
model.getLogicalRelationships().add( rl1 );
return model;
}
示例6: testRatioOfSumsGroupBy
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
/**
* Scenario: we have 2 sums and we want to calculate a ratio.<br>
* The aggregation on the ratio is obviously "none".<br>
* However, the generator has to keep in mind that it still needs to generate a group by.<br>
* <br>
* This is a simple one-table example.<br>
*
*/
@Test
public void testRatioOfSumsGroupBy() throws Exception {
final LogicalModel model = new LogicalModel();
model.setId( "model_01" );
Category mainCat = new Category();
mainCat.setId( "cat_01" );
model.getCategories().add( mainCat );
final LogicalTable bt1 = new LogicalTable();
bt1.setId( "bt1" ); //$NON-NLS-1$
bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "t1" ); //$NON-NLS-1$
// dimension column d1
//
final LogicalColumn d1 = new LogicalColumn();
d1.setId( "d1" ); //$NON-NLS-1$
d1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "d" ); //$NON-NLS-1$
d1.setLogicalTable( bt1 );
d1.setAggregationType( AggregationType.NONE );
d1.setProperty( IPhysicalColumn.FIELDTYPE_PROPERTY, FieldType.DIMENSION );
bt1.addLogicalColumn( d1 );
mainCat.addLogicalColumn( d1 );
// Sum column bc1
//
final LogicalColumn bc1 = new LogicalColumn();
bc1.setId( "bc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "a" ); //$NON-NLS-1$
bc1.setLogicalTable( bt1 );
bc1.setAggregationType( AggregationType.SUM );
bc1.setProperty( IPhysicalColumn.FIELDTYPE_PROPERTY, FieldType.FACT );
bt1.addLogicalColumn( bc1 );
mainCat.addLogicalColumn( bc1 );
// Sum column bc2
//
final LogicalColumn bc2 = new LogicalColumn();
bc2.setId( "bc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "b" ); //$NON-NLS-1$
bc2.setLogicalTable( bt1 );
bc2.setAggregationType( AggregationType.SUM );
bc2.setProperty( IPhysicalColumn.FIELDTYPE_PROPERTY, FieldType.FACT );
bt1.addLogicalColumn( bc2 );
mainCat.addLogicalColumn( bc2 );
// A calculated column: ratio
//
final LogicalColumn ratio = new LogicalColumn();
ratio.setId( "ratio" ); //$NON-NLS-1$
ratio.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "[bt1.bc1] / [bt1.bc2]" ); //$NON-NLS-1$
ratio.setLogicalTable( bt1 );
ratio.setAggregationType( AggregationType.NONE );
ratio.setProperty( SqlPhysicalColumn.TARGET_COLUMN_TYPE, TargetColumnType.OPEN_FORMULA );
ratio.setProperty( IPhysicalColumn.FIELDTYPE_PROPERTY, FieldType.FACT );
bt1.addLogicalColumn( ratio );
mainCat.addLogicalColumn( ratio );
DatabaseMeta databaseMeta = TestHelper.createOracleDatabaseMeta();
Query myTest = new Query( null, model ); //$NON-NLS-1$
myTest.getSelections().add( new Selection( null, d1, null ) );
myTest.getSelections().add( new Selection( null, ratio, null ) );
MappedQuery query = new SqlGenerator().generateSql( myTest, "en_US", null, databaseMeta );
TestHelper.assertEqualsIgnoreWhitespaces(
"SELECT bt1.d AS COL0 , SUM(bt1.a) / SUM(bt1.b) AS COL1 FROM t1 bt1 GROUP BY bt1.d", //$NON-NLS-1$
query.getQuery() );
}
示例7: testOuterJoinScenario1c
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
/**
* Scenario 1c: Two Tables are outer joined with an aggregate constraint
*/
@Test
public void testOuterJoinScenario1c() throws Exception {
final LogicalModel model = new LogicalModel();
model.setId( "model_01" );
Category mainCat = new Category();
mainCat.setId( "cat_01" );
model.getCategories().add( mainCat );
final LogicalTable bt1 = new LogicalTable();
bt1.setId( "bt1" ); //$NON-NLS-1$
bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "pt1" ); //$NON-NLS-1$
final LogicalColumn bc1 = new LogicalColumn();
bc1.setId( "bc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "pc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN_TYPE, TargetColumnType.COLUMN_NAME );
bc1.setLogicalTable( bt1 );
bt1.addLogicalColumn( bc1 );
bt1.setProperty( SqlPhysicalTable.RELATIVE_SIZE, 1 );
mainCat.addLogicalColumn( bc1 );
final LogicalTable bt2 = new LogicalTable();
bt2.setId( "bt2" ); //$NON-NLS-1$
bt2.setProperty( SqlPhysicalTable.TARGET_TABLE, "pt2" ); //$NON-NLS-1$
final LogicalColumn bc2 = new LogicalColumn();
bc2.setId( "bc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "pc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN_TYPE, TargetColumnType.COLUMN_NAME );
bc2.setAggregationType( AggregationType.SUM );
bc2.setLogicalTable( bt2 );
bt2.addLogicalColumn( bc2 );
mainCat.addLogicalColumn( bc2 );
final LogicalRelationship rl1 = new LogicalRelationship();
rl1.setRelationshipType( RelationshipType._0_N );
rl1.setFromTable( bt1 );
rl1.setFromColumn( bc1 );
rl1.setToTable( bt2 );
rl1.setToColumn( bc2 );
model.getLogicalRelationships().add( rl1 );
DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
Query myTest = new Query( null, model ); //$NON-NLS-1$
myTest.getSelections().add( new Selection( null, bc1, null ) );
myTest.getSelections().add( new Selection( null, bc2, null ) );
myTest.getConstraints().add( new Constraint( CombinationType.AND, "[cat_01.bc2] > 1" ) );
SqlGenerator generator = new SqlGenerator();
MappedQuery query = generator.generateSql( myTest, "en_US", null, databaseMeta );
TestHelper
.assertEqualsIgnoreWhitespaces(
"SELECT bt1.pc1 AS COL0 ,SUM(bt2.pc2) AS COL1 FROM pt1 bt1 LEFT OUTER JOIN pt2 bt2 ON ( bt1.pc1 = bt2.pc2 ) GROUP BY bt1.pc1 HAVING ( SUM(bt2.pc2) > 1 )",
query.getQuery() ); //$NON-NLS-1$
}
示例8: generatePhysicalMetadataModel
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
public Domain generatePhysicalMetadataModel() throws KettleException {
// First do some checking and lookups...
//
String targetDatabaseName = ConceptUtil.getString(logicalDomain, DefaultIDs.DOMAIN_TARGET_DATABASE);
if (Utils.isEmpty(targetDatabaseName)) {
throw new KettleException("Please specify a target database!");
}
DatabaseMeta targetDatabaseMeta = DatabaseMeta.findDatabase(databases, targetDatabaseName);
if (targetDatabaseMeta==null) {
throw new KettleException("Target database with name '"+targetDatabaseName+"' can't be found!");
}
// Now start creation of a new domain with physical underpinning.
//
Domain domain = new Domain();
// Copy the domain information...
//
domain.setId( createId("DOMAIN", null, domain) );
domain.setName(logicalDomain.getName());
domain.setDescription(logicalDomain.getDescription());
// Now copy all the models...
//
for (LogicalModel logicalModel : logicalDomain.getLogicalModels()) {
// Copy model information...
//
LogicalModel model = new LogicalModel();
model.setId( createId("MODEL", domain, model));
model.setName(logicalModel.getName());
model.setDescription(logicalModel.getDescription());
// Create a physical model...
//
SqlPhysicalModel sqlModel = new SqlPhysicalModel();
sqlModel.setDatasource(createSqlDataSource(targetDatabaseMeta));
model.setPhysicalModel(sqlModel);
for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
LogicalTable table = new LogicalTable();
table.setId( createId("LOGICAL_TABLE", logicalModel, logicalTable) );
table.setName(logicalTable.getName());
table.setDescription(logicalTable.getDescription());
String targetTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
SqlPhysicalTable sqlTable = new SqlPhysicalTable(sqlModel);
table.setPhysicalTable(sqlTable);
// Copy name & description from physical level...
//
sqlTable.setId( createId("PHYSICAL_TABLE", logicalModel, logicalTable));
sqlTable.setName(logicalTable.getName());
sqlTable.setDescription(logicalTable.getDescription());
sqlTable.setTableType(ConceptUtil.getTableType(logicalTable));
sqlTable.setTargetSchema(targetDatabaseMeta.getPreferredSchemaName());
sqlTable.setTargetTable(targetTable);
}
}
return domain;
}
示例9: getBasicDomain
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
public static Domain getBasicDomain() {
String locale = LocaleHelper.getLocale().toString();
SqlPhysicalModel model = new SqlPhysicalModel();
SqlDataSource dataSource = new SqlDataSource();
dataSource.setDatabaseName( "SampleData" );
model.setDatasource( dataSource );
SqlPhysicalTable table = new SqlPhysicalTable( model );
table.setId( "PT1" );
model.getPhysicalTables().add( table );
table.setTargetTableType( TargetTableType.INLINE_SQL );
table.setTargetTable( "select * from customers" );
SqlPhysicalColumn column = new SqlPhysicalColumn( table );
column.setId( "PC1" );
column.setTargetColumn( "customername" );
column.setName( new LocalizedString( locale, "Customer Name" ) );
column.setDescription( new LocalizedString( locale, "Customer Name Desc" ) );
column.setDataType( DataType.STRING );
table.getPhysicalColumns().add( column );
LogicalModel logicalModel = new LogicalModel();
logicalModel.setId( "MODEL" );
logicalModel.setName( new LocalizedString( locale, "My Model" ) );
logicalModel.setDescription( new LocalizedString( locale, "A Description of the Model" ) );
LogicalTable logicalTable = new LogicalTable();
logicalTable.setId( "LT" );
logicalTable.setPhysicalTable( table );
logicalTable.setLogicalModel( logicalModel );
logicalModel.getLogicalTables().add( logicalTable );
LogicalColumn logicalColumn = new LogicalColumn();
logicalColumn.setId( "LC_CUSTOMERNAME" );
logicalColumn.setPhysicalColumn( column );
logicalColumn.setLogicalTable( logicalTable );
logicalTable.addLogicalColumn( logicalColumn );
Category mainCategory = new Category( logicalModel );
mainCategory.setId( "CATEGORY" );
mainCategory.setName( new LocalizedString( locale, "Category" ) );
mainCategory.addLogicalColumn( logicalColumn );
logicalModel.getCategories().add( mainCategory );
Domain domain = new Domain();
domain.setId( "DOMAIN" );
domain.addPhysicalModel( model );
domain.addLogicalModel( logicalModel );
return domain;
}
示例10: testOuterJoinScenario5b
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
/**
* Scenario 5: Two outer joins in the opposite direction
*/
@Test
public void testOuterJoinScenario5b() throws Exception {
final LogicalModel model = new LogicalModel();
model.setId( "model_01" );
Category mainCat = new Category();
mainCat.setId( "cat_01" );
model.getCategories().add( mainCat );
final LogicalTable bt1 = new LogicalTable();
bt1.setId( "bt1" ); //$NON-NLS-1$
bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "t1" ); //$NON-NLS-1$
final LogicalColumn bc1 = new LogicalColumn();
bc1.setId( "bc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc1.setLogicalTable( bt1 );
bt1.addLogicalColumn( bc1 );
bt1.setProperty( SqlPhysicalTable.RELATIVE_SIZE, 1 );
mainCat.addLogicalColumn( bc1 );
final LogicalTable bt2 = new LogicalTable();
bt2.setId( "bt2" ); //$NON-NLS-1$
bt2.setProperty( SqlPhysicalTable.TARGET_TABLE, "t2" ); //$NON-NLS-1$
final LogicalColumn bc2 = new LogicalColumn();
bc2.setId( "bc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc2.setLogicalTable( bt2 );
bt2.addLogicalColumn( bc2 );
mainCat.addLogicalColumn( bc2 );
final LogicalTable bt3 = new LogicalTable();
bt3.setId( "bt3" ); //$NON-NLS-1$
bt3.setProperty( SqlPhysicalTable.TARGET_TABLE, "t3" ); //$NON-NLS-1$
final LogicalColumn bc3 = new LogicalColumn();
bc3.setId( "bc3" ); //$NON-NLS-1$
bc3.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc3.setLogicalTable( bt3 );
bt3.addLogicalColumn( bc3 );
mainCat.addLogicalColumn( bc3 );
final LogicalRelationship rl1 = new LogicalRelationship();
rl1.setRelationshipType( RelationshipType._N_0 );
rl1.setJoinOrderKey( "B" );
rl1.setFromTable( bt1 );
rl1.setFromColumn( bc1 );
rl1.setToTable( bt2 );
rl1.setToColumn( bc2 );
model.getLogicalRelationships().add( rl1 );
final LogicalRelationship rl2 = new LogicalRelationship();
rl2.setRelationshipType( RelationshipType._N_0 );
rl2.setJoinOrderKey( "A" );
rl2.setFromTable( bt1 );
rl2.setFromColumn( bc1 );
rl2.setToTable( bt3 );
rl2.setToColumn( bc3 );
model.getLogicalRelationships().add( rl2 );
DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
Query myTest = new Query( null, model ); //$NON-NLS-1$
myTest.getSelections().add( new Selection( null, bc1, null ) );
myTest.getSelections().add( new Selection( null, bc2, null ) );
myTest.getSelections().add( new Selection( null, bc3, null ) );
SqlGenerator generator = new SqlGenerator();
MappedQuery query = generator.generateSql( myTest, "en_US", null, databaseMeta );
TestHelper
.assertEqualsIgnoreWhitespaces(
"SELECT DISTINCT bt1.k AS COL0 ,bt2.k AS COL1 ,bt3.k AS COL2 FROM t2 bt2 LEFT OUTER JOIN ( t1 bt1 RIGHT OUTER JOIN t3 bt3 ON ( bt1.k = bt3.k ) ) ON ( bt1.k = bt2.k )",
query.getQuery() ); //$NON-NLS-1$
}
示例11: testOuterJoinScenario1c
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
/**
* Scenario 1c: Two Tables are outer joined with an aggregate constraint
*/
@Test
public void testOuterJoinScenario1c() throws Exception {
final LogicalModel model = new LogicalModel();
model.setId( "model_01" );
Category mainCat = new Category();
mainCat.setId( "cat_01" );
model.getCategories().add( mainCat );
final LogicalTable bt1 = new LogicalTable();
bt1.setId( "bt1" ); //$NON-NLS-1$
bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "pt1" ); //$NON-NLS-1$
final LogicalColumn bc1 = new LogicalColumn();
bc1.setId( "bc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "pc1" ); //$NON-NLS-1$
bc1.setLogicalTable( bt1 );
bt1.addLogicalColumn( bc1 );
bt1.setProperty( SqlPhysicalTable.RELATIVE_SIZE, 1 );
mainCat.addLogicalColumn( bc1 );
final LogicalTable bt2 = new LogicalTable();
bt2.setId( "bt2" ); //$NON-NLS-1$
bt2.setProperty( SqlPhysicalTable.TARGET_TABLE, "pt2" ); //$NON-NLS-1$
final LogicalColumn bc2 = new LogicalColumn();
bc2.setId( "bc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "pc2" ); //$NON-NLS-1$
bc2.setAggregationType( AggregationType.SUM );
bc2.setLogicalTable( bt2 );
bt2.addLogicalColumn( bc2 );
mainCat.addLogicalColumn( bc2 );
final LogicalRelationship rl1 = new LogicalRelationship();
rl1.setRelationshipType( RelationshipType._0_N );
rl1.setFromTable( bt1 );
rl1.setFromColumn( bc1 );
rl1.setToTable( bt2 );
rl1.setToColumn( bc2 );
model.getLogicalRelationships().add( rl1 );
DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
Query myTest = new Query( null, model ); //$NON-NLS-1$
myTest.getSelections().add( new AliasedSelection( null, bc1, null, null ) );
myTest.getSelections().add( new AliasedSelection( null, bc2, null, null ) );
myTest.getConstraints().add( new Constraint( CombinationType.AND, "[cat_01.bc2] > 1" ) );
MappedQuery query = new AdvancedSqlGenerator().generateSql( myTest, "en_US", null, databaseMeta );
TestHelper
.assertEqualsIgnoreWhitespaces(
"SELECT bt1.pc1 AS COL0 ,SUM(bt2.pc2) AS COL1 FROM pt1 bt1 LEFT OUTER JOIN pt2 bt2 ON ( bt1.pc1 = bt2.pc2 ) GROUP BY bt1.pc1 HAVING ( SUM(bt2.pc2) > 1 )",
query.getQuery() ); //$NON-NLS-1$
}
示例12: testOuterJoinScenario3
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
/**
* Scenario 3: Three Tables are outer joined
*/
@Test
public void testOuterJoinScenario3() throws Exception {
final LogicalModel model = new LogicalModel();
model.setId( "model_01" );
Category mainCat = new Category();
mainCat.setId( "cat_01" );
model.getCategories().add( mainCat );
final LogicalTable bt1 = new LogicalTable();
bt1.setId( "bt1" ); //$NON-NLS-1$
bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "t1" ); //$NON-NLS-1$
final LogicalColumn bc1 = new LogicalColumn();
bc1.setId( "bc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc1.setLogicalTable( bt1 );
bt1.addLogicalColumn( bc1 );
bt1.setProperty( SqlPhysicalTable.RELATIVE_SIZE, 1 );
mainCat.addLogicalColumn( bc1 );
final LogicalTable bt2 = new LogicalTable();
bt2.setId( "bt2" ); //$NON-NLS-1$
bt2.setProperty( SqlPhysicalTable.TARGET_TABLE, "t2" ); //$NON-NLS-1$
final LogicalColumn bc2 = new LogicalColumn();
bc2.setId( "bc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc2.setLogicalTable( bt2 );
bt2.addLogicalColumn( bc2 );
mainCat.addLogicalColumn( bc2 );
final LogicalTable bt3 = new LogicalTable();
bt3.setId( "bt3" ); //$NON-NLS-1$
bt3.setProperty( SqlPhysicalTable.TARGET_TABLE, "t3" ); //$NON-NLS-1$
final LogicalColumn bc3 = new LogicalColumn();
bc3.setId( "bc3" ); //$NON-NLS-1$
bc3.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc3.setLogicalTable( bt3 );
bt3.addLogicalColumn( bc3 );
mainCat.addLogicalColumn( bc3 );
final LogicalRelationship rl1 = new LogicalRelationship();
rl1.setRelationshipType( RelationshipType._0_N );
rl1.setFromTable( bt1 );
rl1.setFromColumn( bc1 );
rl1.setToTable( bt2 );
rl1.setToColumn( bc2 );
model.getLogicalRelationships().add( rl1 );
final LogicalRelationship rl2 = new LogicalRelationship();
rl2.setRelationshipType( RelationshipType._0_N );
rl2.setFromTable( bt2 );
rl2.setFromColumn( bc2 );
rl2.setToTable( bt3 );
rl2.setToColumn( bc3 );
model.getLogicalRelationships().add( rl2 );
DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
Query myTest = new Query( null, model ); //$NON-NLS-1$
myTest.getSelections().add( new Selection( null, bc1, null ) );
myTest.getSelections().add( new Selection( null, bc2, null ) );
myTest.getSelections().add( new Selection( null, bc3, null ) );
SqlGenerator generator = new SqlGenerator();
MappedQuery query = generator.generateSql( myTest, "en_US", null, databaseMeta );
TestHelper
.assertEqualsIgnoreWhitespaces(
"SELECT DISTINCT bt1.k AS COL0 ,bt2.k AS COL1 ,bt3.k AS COL2 FROM t1 bt1 LEFT OUTER JOIN ( t2 bt2 LEFT OUTER JOIN t3 bt3 ON ( bt2.k = bt3.k ) ) ON ( bt1.k = bt2.k )",
query.getQuery() ); //$NON-NLS-1$
}
示例13: testOuterJoinScenario3
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
/**
* Scenario 3: Three Tables are outer joined
*/
@Test
public void testOuterJoinScenario3() throws Exception {
final LogicalModel model = new LogicalModel();
model.setId( "model_01" );
Category mainCat = new Category();
mainCat.setId( "cat_01" );
model.getCategories().add( mainCat );
final LogicalTable bt1 = new LogicalTable();
bt1.setId( "bt1" ); //$NON-NLS-1$
bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "t1" ); //$NON-NLS-1$
final LogicalColumn bc1 = new LogicalColumn();
bc1.setId( "bc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc1.setLogicalTable( bt1 );
bt1.addLogicalColumn( bc1 );
bt1.setProperty( SqlPhysicalTable.RELATIVE_SIZE, 1 );
mainCat.addLogicalColumn( bc1 );
final LogicalTable bt2 = new LogicalTable();
bt2.setId( "bt2" ); //$NON-NLS-1$
bt2.setProperty( SqlPhysicalTable.TARGET_TABLE, "t2" ); //$NON-NLS-1$
final LogicalColumn bc2 = new LogicalColumn();
bc2.setId( "bc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc2.setLogicalTable( bt2 );
bt2.addLogicalColumn( bc2 );
mainCat.addLogicalColumn( bc2 );
final LogicalTable bt3 = new LogicalTable();
bt3.setId( "bt3" ); //$NON-NLS-1$
bt3.setProperty( SqlPhysicalTable.TARGET_TABLE, "t3" ); //$NON-NLS-1$
final LogicalColumn bc3 = new LogicalColumn();
bc3.setId( "bc3" ); //$NON-NLS-1$
bc3.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc3.setLogicalTable( bt3 );
bt3.addLogicalColumn( bc3 );
mainCat.addLogicalColumn( bc3 );
final LogicalRelationship rl1 = new LogicalRelationship();
rl1.setRelationshipType( RelationshipType._0_N );
rl1.setFromTable( bt1 );
rl1.setFromColumn( bc1 );
rl1.setToTable( bt2 );
rl1.setToColumn( bc2 );
model.getLogicalRelationships().add( rl1 );
final LogicalRelationship rl2 = new LogicalRelationship();
rl2.setRelationshipType( RelationshipType._0_N );
rl2.setFromTable( bt2 );
rl2.setFromColumn( bc2 );
rl2.setToTable( bt3 );
rl2.setToColumn( bc3 );
model.getLogicalRelationships().add( rl2 );
DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
Query myTest = new Query( null, model ); //$NON-NLS-1$
myTest.getSelections().add( new AliasedSelection( null, bc1, null, null ) );
myTest.getSelections().add( new AliasedSelection( null, bc2, null, null ) );
myTest.getSelections().add( new AliasedSelection( null, bc3, null, null ) );
MappedQuery query = new AdvancedSqlGenerator().generateSql( myTest, "en_US", null, databaseMeta );
TestHelper
.assertEqualsIgnoreWhitespaces(
"SELECT DISTINCT bt1.k AS COL0 ,bt2.k AS COL1 ,bt3.k AS COL2 FROM t1 bt1 LEFT OUTER JOIN ( t2 bt2 LEFT OUTER JOIN t3 bt3 ON ( bt2.k = bt3.k ) ) ON ( bt1.k = bt2.k )",
query.getQuery() ); //$NON-NLS-1$
}
示例14: testOuterJoinScenario4
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
/**
* Scenario 4: Two outer joins on a single table
*/
@Test
public void testOuterJoinScenario4() throws Exception {
final LogicalModel model = new LogicalModel();
model.setId( "model_01" );
Category mainCat = new Category();
mainCat.setId( "cat_01" );
model.getCategories().add( mainCat );
final LogicalTable bt1 = new LogicalTable();
bt1.setId( "bt1" ); //$NON-NLS-1$
bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "t1" ); //$NON-NLS-1$
final LogicalColumn bc1 = new LogicalColumn();
bc1.setId( "bc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc1.setLogicalTable( bt1 );
bt1.addLogicalColumn( bc1 );
bt1.setProperty( SqlPhysicalTable.RELATIVE_SIZE, 1 );
mainCat.addLogicalColumn( bc1 );
final LogicalTable bt2 = new LogicalTable();
bt2.setId( "bt2" ); //$NON-NLS-1$
bt2.setProperty( SqlPhysicalTable.TARGET_TABLE, "t2" ); //$NON-NLS-1$
final LogicalColumn bc2 = new LogicalColumn();
bc2.setId( "bc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc2.setLogicalTable( bt2 );
bt2.addLogicalColumn( bc2 );
mainCat.addLogicalColumn( bc2 );
final LogicalTable bt3 = new LogicalTable();
bt3.setId( "bt3" ); //$NON-NLS-1$
bt3.setProperty( SqlPhysicalTable.TARGET_TABLE, "t3" ); //$NON-NLS-1$
final LogicalColumn bc3 = new LogicalColumn();
bc3.setId( "bc3" ); //$NON-NLS-1$
bc3.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc3.setLogicalTable( bt3 );
bt3.addLogicalColumn( bc3 );
mainCat.addLogicalColumn( bc3 );
final LogicalRelationship rl1 = new LogicalRelationship();
rl1.setRelationshipType( RelationshipType._0_N );
rl1.setFromTable( bt1 );
rl1.setFromColumn( bc1 );
rl1.setToTable( bt2 );
rl1.setToColumn( bc2 );
model.getLogicalRelationships().add( rl1 );
final LogicalRelationship rl2 = new LogicalRelationship();
rl2.setRelationshipType( RelationshipType._0_N );
rl2.setFromTable( bt1 );
rl2.setFromColumn( bc1 );
rl2.setToTable( bt3 );
rl2.setToColumn( bc3 );
model.getLogicalRelationships().add( rl2 );
DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
Query myTest = new Query( null, model ); //$NON-NLS-1$
myTest.getSelections().add( new AliasedSelection( null, bc1, null, null ) );
myTest.getSelections().add( new AliasedSelection( null, bc2, null, null ) );
myTest.getSelections().add( new AliasedSelection( null, bc3, null, null ) );
MappedQuery query = new AdvancedSqlGenerator().generateSql( myTest, "en_US", null, databaseMeta );
TestHelper
.assertEqualsIgnoreWhitespaces(
"SELECT DISTINCT bt1.k AS COL0 ,bt2.k AS COL1 ,bt3.k AS COL2 FROM t2 bt2 RIGHT OUTER JOIN ( t1 bt1 LEFT OUTER JOIN t3 bt3 ON ( bt1.k = bt3.k ) ) ON ( bt1.k = bt2.k )",
query.getQuery() ); //$NON-NLS-1$
}
示例15: testOuterJoinScenario5a
import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
/**
* Scenario 5: Two outer joins in the opposite direction
*/
@Test
public void testOuterJoinScenario5a() throws Exception {
final LogicalModel model = new LogicalModel();
model.setId( "model_01" );
Category mainCat = new Category();
mainCat.setId( "cat_01" );
model.getCategories().add( mainCat );
final LogicalTable bt1 = new LogicalTable();
bt1.setId( "bt1" ); //$NON-NLS-1$
bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "t1" ); //$NON-NLS-1$
final LogicalColumn bc1 = new LogicalColumn();
bc1.setId( "bc1" ); //$NON-NLS-1$
bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc1.setLogicalTable( bt1 );
bt1.addLogicalColumn( bc1 );
bt1.setProperty( SqlPhysicalTable.RELATIVE_SIZE, 1 );
mainCat.addLogicalColumn( bc1 );
final LogicalTable bt2 = new LogicalTable();
bt2.setId( "bt2" ); //$NON-NLS-1$
bt2.setProperty( SqlPhysicalTable.TARGET_TABLE, "t2" ); //$NON-NLS-1$
final LogicalColumn bc2 = new LogicalColumn();
bc2.setId( "bc2" ); //$NON-NLS-1$
bc2.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc2.setLogicalTable( bt2 );
bt2.addLogicalColumn( bc2 );
mainCat.addLogicalColumn( bc2 );
final LogicalTable bt3 = new LogicalTable();
bt3.setId( "bt3" ); //$NON-NLS-1$
bt3.setProperty( SqlPhysicalTable.TARGET_TABLE, "t3" ); //$NON-NLS-1$
final LogicalColumn bc3 = new LogicalColumn();
bc3.setId( "bc3" ); //$NON-NLS-1$
bc3.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "k" ); //$NON-NLS-1$
bc3.setLogicalTable( bt3 );
bt3.addLogicalColumn( bc3 );
mainCat.addLogicalColumn( bc3 );
final LogicalRelationship rl1 = new LogicalRelationship();
rl1.setRelationshipType( RelationshipType._N_0 );
rl1.setJoinOrderKey( "A" );
rl1.setFromTable( bt1 );
rl1.setFromColumn( bc1 );
rl1.setToTable( bt2 );
rl1.setToColumn( bc2 );
model.getLogicalRelationships().add( rl1 );
final LogicalRelationship rl2 = new LogicalRelationship();
rl2.setRelationshipType( RelationshipType._N_0 );
rl2.setJoinOrderKey( "B" );
rl2.setFromTable( bt1 );
rl2.setFromColumn( bc1 );
rl2.setToTable( bt3 );
rl2.setToColumn( bc3 );
model.getLogicalRelationships().add( rl2 );
DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
Query myTest = new Query( null, model ); //$NON-NLS-1$
myTest.getSelections().add( new AliasedSelection( null, bc1, null, null ) );
myTest.getSelections().add( new AliasedSelection( null, bc2, null, null ) );
myTest.getSelections().add( new AliasedSelection( null, bc3, null, null ) );
MappedQuery query = new AdvancedSqlGenerator().generateSql( myTest, "en_US", null, databaseMeta );
TestHelper
.assertEqualsIgnoreWhitespaces(
"SELECT DISTINCT bt1.k AS COL0 ,bt2.k AS COL1 ,bt3.k AS COL2 FROM t3 bt3 LEFT OUTER JOIN ( t1 bt1 RIGHT OUTER JOIN t2 bt2 ON ( bt1.k = bt2.k ) ) ON ( bt1.k = bt3.k )",
query.getQuery() ); //$NON-NLS-1$
}