当前位置: 首页>>代码示例>>Java>>正文


Java LogicalModel.findLogicalColumn方法代码示例

本文整理汇总了Java中org.pentaho.metadata.model.LogicalModel.findLogicalColumn方法的典型用法代码示例。如果您正苦于以下问题:Java LogicalModel.findLogicalColumn方法的具体用法?Java LogicalModel.findLogicalColumn怎么用?Java LogicalModel.findLogicalColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.pentaho.metadata.model.LogicalModel的用法示例。


在下文中一共展示了LogicalModel.findLogicalColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAliasedJoin2

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testAliasedJoin2() throws Exception {

  LogicalModel model = getDefaultModel();
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" ); //$NON-NLS-1$
  LogicalColumn bc3 = model.findLogicalColumn( "bc3" ); //$NON-NLS-1$

  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$
  Query myTest = new Query( null, model );

  myTest.getSelections().add( new AliasedSelection( null, bc1, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( null, bc3, null, null ) );

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          bt1_alias1.pc1 AS COL0\n"
      + "         ,bt3.pc3 AS COL1\n" + "FROM \n" + "          pt3 bt3\n" + "         ,pt1 bt1_alias1\n"
      + "         ,pt2 bt2_alias1\n" + "WHERE \n" + "          (\n"
      + "             bt1_alias1.pc1 = bt2_alias1.pc2\n" + "          )\n" + "      AND (\n"
      + "             bt3.pc3 = bt2_alias1.pc2\n" + "          )\n", new AdvancedSqlGenerator().generateSql( myTest,
      "en_US", null, databaseMeta ).getQuery() );
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:21,代码来源:AdvancedQueryIT.java

示例2: testModelAggFunctions

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testModelAggFunctions() throws Exception {
  LogicalModel model = getDefaultModel();
  LogicalColumn bc2 = model.findLogicalColumn( "bc2" ); //$NON-NLS-1$
  LogicalColumn bcs1 = model.findLogicalColumn( "bcs1" ); //$NON-NLS-1$

  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$
  Query myTest = new Query( null, model );

  myTest.getSelections().add( new AliasedSelection( null, bcs1, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( null, bc2, null, null ) );
  myTest.getSelections().add( new AliasedSelection( null, bcs1, null, null ) );

  myTest.getConstraints().add( new Constraint( CombinationType.AND, "[bt2.bc2] > 10" ) );
  myTest.getConstraints().add( new Constraint( CombinationType.AND, "[alias1.bcs1] >= 30" ) );
  // SQLQueryTest.printOutJava(new AdvancedSqlGenerator().generateSql(myTest, "en_US", null,
  // databaseMeta).getQuery());
  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT \n" + "          SUM(bt1_alias1.pc1) AS COL0\n"
      + "         ,bt2.pc2 AS COL1\n" + "         ,SUM(bt1.pc1) AS COL2\n" + "FROM \n" + "          pt1 bt1\n"
      + "         ,pt2 bt2\n" + "         ,pt1 bt1_alias1\n" + "WHERE \n" + "          (\n"
      + "             bt1.pc1 = bt2.pc2\n" + "          )\n" + "      AND (\n"
      + "             bt1_alias1.pc1 = bt2.pc2\n" + "          )\n" + "      AND ((\n"
      + "              bt2.pc2  > 10\n" + "          ))\n" + "GROUP BY \n" + "          bt2.pc2\n" + "HAVING \n"
      + "          (\n" + "              SUM(bt1_alias1.pc1)  >= 30\n" + "          )\n", new AdvancedSqlGenerator()
      .generateSql( myTest, "en_US", null, databaseMeta ).getQuery() );
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:27,代码来源:AdvancedQueryIT.java

示例3: testLimitedQuery

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testLimitedQuery() throws Exception {
  LogicalModel model = TestHelper.buildDefaultModel();
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" );
  DatabaseMeta databaseMeta = new DatabaseMeta( "", "HYPERSONIC", "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 query = new Query( null, model );
  query.setLimit( 10 );

  query.getSelections().add( new Selection( null, bc1, null ) );

  SqlGenerator generator = new SqlGenerator();

  MappedQuery mquery = generator.generateSql( query, "en_US", null, databaseMeta );

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT TOP 10 DISTINCT bt1.pc1 AS COL0 FROM pt1 bt1", mquery.getQuery() );
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:17,代码来源:SqlGeneratorIT.java

示例4: testAliasedJoin

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testAliasedJoin() throws Exception {

  LogicalModel model = getDefaultModel();
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" ); //$NON-NLS-1$
  LogicalColumn bc3 = model.findLogicalColumn( "bc3" ); //$NON-NLS-1$

  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$
  Query myTest = new Query( null, model );

  myTest.getSelections().add( new AliasedSelection( null, bc1, null, null ) );
  myTest.getSelections().add( new AliasedSelection( null, bc1, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( null, bc3, null, null ) );
  myTest.getSelections().add( new AliasedSelection( "[alias1.bc1] * 3" ) );

  myTest.getConstraints().add( new Constraint( CombinationType.AND, "[alias1.bc1] > 10" ) );
  myTest.getConstraints().add( new Constraint( CombinationType.AND, "[bt3.bc3] > 10" ) );

  // SQLQueryTest.printOutJava(new AdvancedSqlGenerator().generateSql(myTest, "en_US", null,
  // databaseMeta).getQuery());
  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT " + "bt1.pc1 AS COL0 ," + "bt1_alias1.pc1 AS COL1 ,"
      + "bt3.pc3 AS COL2 , " + "bt1_alias1.pc1 * 3 AS COL3 " + "FROM " + "pt1 bt1 ," + "pt2 bt2 ," + "pt3 bt3 ,"
      + "pt1 bt1_alias1 ," + "pt2 bt2_alias1 " + "WHERE " + "( bt1.pc1 = bt2.pc2 ) " + "AND ( bt3.pc3 = bt2.pc2 ) "
      + "AND ( bt1_alias1.pc1 = bt2_alias1.pc2 ) " + "AND ( bt3.pc3 = bt2_alias1.pc2 ) "
      + "AND (( bt1_alias1.pc1 > 10 ) " + "AND ( bt3.pc3 > 10 ))", new AdvancedSqlGenerator().generateSql( myTest,
      "en_US", null, databaseMeta ).getQuery() );
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:28,代码来源:AdvancedQueryIT.java

示例5: testQueryAggFunctions

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testQueryAggFunctions() throws Exception {

  LogicalModel model = getDefaultModel();
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" ); //$NON-NLS-1$
  LogicalColumn bc3 = model.findLogicalColumn( "bc3" ); //$NON-NLS-1$

  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$
  Query myTest = new Query( null, model );

  myTest.getSelections().add( new AliasedSelection( null, bc1, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( "SUM([bt3.bc3])" ) );

  myTest.getConstraints().add( new Constraint( CombinationType.AND, "SUM([bt3.bc3]) > 30" ) );

  myTest.getOrders().add( new Order( new AliasedSelection( "SUM([bt3.bc3])" ), Type.ASC ) );

  // SQLQueryTest.printOutJava(new AdvancedSqlGenerator().generateSql(myTest, "en_US", null,
  // databaseMeta).getQuery());

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT \n" + "          bt1_alias1.pc1 AS COL0\n"
      + "         , SUM( bt3.pc3 ) AS COL1\n" + "FROM \n" + "          pt3 bt3\n" + "         ,pt1 bt1_alias1\n"
      + "         ,pt2 bt2_alias1\n" + "WHERE \n" + "          (\n"
      + "             bt1_alias1.pc1 = bt2_alias1.pc2\n" + "          )\n" + "      AND (\n"
      + "             bt3.pc3 = bt2_alias1.pc2\n" + "          )\n" + "GROUP BY \n" + "          bt1_alias1.pc1\n"
      + "HAVING \n" + "          (\n" + "              SUM( bt3.pc3 ) > 30\n" + "          )\n" + "ORDER BY \n"
      + "           SUM( bt3.pc3 )\n", new AdvancedSqlGenerator().generateSql( myTest, "en_US", null, databaseMeta )
      .getQuery() );
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:30,代码来源:AdvancedQueryIT.java

示例6: testModelFunctions

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testModelFunctions() throws Exception {
  LogicalModel model = getDefaultModel();
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" ); //$NON-NLS-1$
  LogicalColumn bce2 = model.findLogicalColumn( "bce2" ); //$NON-NLS-1$

  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$
  Query myTest = new Query( null, model );

  myTest.getSelections().add( new AliasedSelection( null, bce2, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( null, bc1, null, null ) );
  myTest.getSelections().add( new AliasedSelection( null, bce2, null, null ) );

  myTest.getOrders().add( new Order( new AliasedSelection( null, bc1, null, null ), Type.ASC ) );
  myTest.getOrders().add( new Order( new AliasedSelection( null, bce2, null, "alias1" ), Type.ASC ) );

  myTest.getConstraints().add( new Constraint( CombinationType.OR, "[alias1.bce2] > 10" ) );
  // SQLQueryTest.printOutJava(new AdvancedSqlGenerator().generateSql(myTest, "en_US", null,
  // databaseMeta).getQuery());
  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "           bt2_alias1.pc2  * 2 AS COL0\n"
      + "         ,bt1.pc1 AS COL1\n" + "         , bt2.pc2  * 2 AS COL2\n" + "FROM \n" + "          pt1 bt1\n"
      + "         ,pt2 bt2\n" + "         ,pt2 bt2_alias1\n" + "WHERE \n" + "          (\n"
      + "             bt1.pc1 = bt2.pc2\n" + "          )\n" + "      AND (\n"
      + "             bt1.pc1 = bt2_alias1.pc2\n" + "          )\n" + "      AND ((\n"
      + "               bt2_alias1.pc2  * 2  > 10\n" + "          ))\n" + "ORDER BY \n" + "          bt1.pc1\n"
      + "         , bt2_alias1.pc2  * 2\n", new AdvancedSqlGenerator().generateSql( myTest, "en_US", null,
      databaseMeta ).getQuery() );
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:29,代码来源:AdvancedQueryIT.java

示例7: testOrderByQuotedSQLGeneration

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testOrderByQuotedSQLGeneration() {
  try {

    LogicalModel model = TestHelper.buildDefaultModel();
    LogicalColumn bc1 = model.findLogicalColumn( "bc1" );
    bc1.setProperty( IPhysicalColumn.AGGREGATIONTYPE_PROPERTY, AggregationType.SUM );
    LogicalColumn bc2 = model.findLogicalColumn( "bc2" );
    LogicalColumn bce2 = model.findLogicalColumn( "bce2" );
    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$
    databaseMeta.setQuoteAllFields( true );
    Query query = new Query( null, model );

    query.getSelections().add( new Selection( null, bc1, null ) );
    query.getSelections().add( new Selection( null, bc2, null ) );
    query.getSelections().add( new Selection( null, bce2, null ) );

    query.getConstraints().add( new Constraint( CombinationType.AND, "[bt1.bc1] > 25" ) ); //$NON-NLS-1$

    query.getOrders().add( new Order( new Selection( null, bc1, null ), Type.ASC ) );

    SqlGenerator generator = new SqlGenerator();

    MappedQuery mquery = generator.generateSql( query, "en_US", null, databaseMeta );
    // TestHelper.printOutJava(mquery.getQuery());

    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT \n" + "          SUM(\"bt1\".\"pc1\") AS \"COL0\"\n"
        + "         ,\"bt2\".\"pc2\" AS \"COL1\"\n" + "         , \"bt2\".\"pc2\"  * 2 AS \"COL2\"\n" + "FROM \n"
        + "          \"pt1\" \"bt1\"\n" + "         ,\"pt2\" \"bt2\"\n" + "WHERE \n"
        + "          ( \"bt1\".\"pc1\" = \"bt2\".\"pc2\" )\n" + "GROUP BY \n" + "          \"bt2\".\"pc2\"\n"
        + "         , \"bt2\".\"pc2\"  * 2\n" + "HAVING \n" + "          (\n"
        + "              SUM(\"bt1\".\"pc1\")  > 25\n" + "          )\n" + "ORDER BY \n" + "          \"COL0\"\n",
        mquery.getQuery() );

  } catch ( Exception e ) {
    e.printStackTrace();
    Assert.fail();
  }
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:40,代码来源:SqlGeneratorIT.java

示例8: testEscapeQuotes

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testEscapeQuotes() {
  try {

    LogicalModel model = TestHelper.buildDefaultModel();
    LogicalColumn bc1 = model.findLogicalColumn( "bc1" );
    LogicalColumn bc2 = model.findLogicalColumn( "bc2" );
    DatabaseMeta databaseMeta = new DatabaseMeta( "", "HYPERSONIC", "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$
    databaseMeta.setQuoteAllFields( true );
    Query query = new Query( null, model );

    query.getSelections().add( new Selection( null, bc1, null ) );
    query.getSelections().add( new Selection( null, bc2, null ) );

    query.getConstraints().add( new Constraint( CombinationType.AND, "CONTAINS([bt1.bc1];\"a'b\")" ) ); //$NON-NLS-1$

    SqlGenerator generator = new SqlGenerator();

    MappedQuery mquery = generator.generateSql( query, "en_US", null, databaseMeta );

    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          \"bt1\".\"pc1\" AS \"COL0\"\n"
        + "         ,\"bt2\".\"pc2\" AS \"COL1\"\n" + "FROM \n" + "          \"pt1\" \"bt1\"\n"
        + "         ,\"pt2\" \"bt2\"\n" + "WHERE \n" + "          ( \"bt1\".\"pc1\" = \"bt2\".\"pc2\" )\n"
        + "      AND \n" + "        (\n" + "          (\n"
        + "              \"bt1\".\"pc1\"  LIKE '%' || 'a''b' || '%'\n" + "          )\n" + "        )\n", mquery
        .getQuery() );

  } catch ( Exception e ) {
    e.printStackTrace();
    Assert.fail();
  }
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:33,代码来源:SqlGeneratorIT.java

示例9: testMultiParameterSqlGeneration_IN_operator

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testMultiParameterSqlGeneration_IN_operator() throws Exception {

  LogicalModel model = TestHelper.buildDefaultModel();
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" );
  LogicalColumn bc2 = model.findLogicalColumn( "bc2" );
  LogicalColumn bc3 = model.findLogicalColumn( "bc3" );
  LogicalColumn bce2 = model.findLogicalColumn( "bce2" );
  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 query = new Query( null, model );

  query.getParameters().add( new Parameter( "test1", DataType.NUMERIC, new Double[] { 1.2, 1.3 } ) );
  query.getParameters().add( new Parameter( "test2", DataType.STRING, new String[] { "value", "value2" } ) ); //$NON-NLS-1$ //$NON-NLS-2$
  query.getParameters().add( new Parameter( "test3", DataType.STRING, "single" ) ); //$NON-NLS-1$

  query.getSelections().add( new Selection( null, bc1, null ) );
  query.getSelections().add( new Selection( null, bc2, null ) );
  query.getSelections().add( new Selection( null, bc3, null ) );

  query.getConstraints().add( new Constraint( CombinationType.AND, "IN([bt1.bc1];[param:test1])" ) ); //$NON-NLS-1$
  query.getConstraints().add( new Constraint( CombinationType.AND, "IN([bt2.bc2];[param:test2])" ) ); //$NON-NLS-1$
  query.getConstraints().add( new Constraint( CombinationType.AND, "IN([bt3.bc3];[param:test3])" ) ); //$NON-NLS-1$

  SqlGenerator generator = new SqlGenerator();

  MappedQuery mquery = generator.generateSql( query, "en_US", null, databaseMeta, null, false );
  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          bt1.pc1 AS COL0\n"
      + "         ,bt2.pc2 AS COL1\n" + "         ,bt3.pc3 AS COL2\n" + "FROM \n" + "          pt1 bt1\n"
      + "         ,pt2 bt2\n" + "         ,pt3 bt3\n" + "WHERE \n" + "          ( bt1.pc1 = bt2.pc2 )\n"
      + "      AND ( bt2.pc2 = bt3.pc3 )\n" + "      AND \n" + "        (\n" + "          (\n"
      + "              bt1.pc1  IN ( 1.2 , 1.3 ) \n" + "          )\n" + "      AND (\n"
      + "              bt2.pc2  IN ( 'value' , 'value2' ) \n" + "          )\n" + "      AND (\n"
      + "              bt3.pc3  IN ( 'single' ) \n" + "          )\n" + "        )\n", mquery.getQuery() );
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:35,代码来源:SqlGeneratorIT.java

示例10: testPreProcessedQuery

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testPreProcessedQuery() {
  try {

    LogicalModel model = TestHelper.buildDefaultModel();
    LogicalColumn bc1 = model.findLogicalColumn( "bc1" );
    LogicalColumn bc2 = model.findLogicalColumn( "bc2" );
    DatabaseMeta databaseMeta = new DatabaseMeta( "", "HYPERSONIC", "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$
    databaseMeta.setQuoteAllFields( true );
    Query query = new Query( null, model );

    query.getSelections().add( new Selection( null, bc1, null ) );
    query.getSelections().add( new Selection( null, bc2, null ) );

    query.getConstraints().add( new Constraint( CombinationType.AND_NOT, "[bt1.bc1] > 1" ) ); //$NON-NLS-1$

    SqlGenerator generator = new TestPreSqlGenerator();

    MappedQuery mquery = generator.generateSql( query, "en_US", null, databaseMeta );

    // TestHelper.printOutJava(mquery.getQuery());

    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          \"bt1\".\"pc1\" AS \"COL0\"\n"
        + "         ,\"bt2\".\"pc2\" AS \"COL1\"\n" + "FROM \n" + "          \"pt1\" \"bt1\"\n"
        + "         ,\"pt2\" \"bt2\"\n" + "WHERE \n" + "          ( \"bt1\".\"pc1\" = \"bt2\".\"pc2\" )\n"
        + "      AND \n" + "        (\n" + "      NOT (\n" + "              \"bt1\".\"pc1\"  > 1\n" + "          )\n"
        + "      AND NOT (\n" + "              \"bt1\".\"pc1\"  < 1\n" + "          )\n" + "        )\n", mquery
        .getQuery() );

  } catch ( Exception e ) {
    e.printStackTrace();
    Assert.fail();
  }
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:35,代码来源:SqlGeneratorIT.java

示例11: testPostProcessedQuery

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testPostProcessedQuery() {
  try {

    LogicalModel model = TestHelper.buildDefaultModel();
    LogicalColumn bc1 = model.findLogicalColumn( "bc1" );
    LogicalColumn bc2 = model.findLogicalColumn( "bc2" );
    DatabaseMeta databaseMeta = new DatabaseMeta( "", "HYPERSONIC", "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$
    databaseMeta.setQuoteAllFields( true );
    Query query = new Query( null, model );

    query.getSelections().add( new Selection( null, bc1, null ) );
    query.getSelections().add( new Selection( null, bc2, null ) );

    query.getConstraints().add( new Constraint( CombinationType.AND_NOT, "[bt1.bc1] > 1" ) ); //$NON-NLS-1$

    SqlGenerator generator = new TestPostSqlGenerator();

    MappedQuery mquery = generator.generateSql( query, "en_US", null, databaseMeta );

    Assert.assertEquals( "Totally bogus", mquery.getQuery() );

    // TestHelper.printOutJava(mquery.getQuery());

  } catch ( Exception e ) {
    e.printStackTrace();
    Assert.fail();
  }
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:30,代码来源:SqlGeneratorIT.java

示例12: testXmlReadingWriting

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
/**
 * this test generates an advanced mqlquery, generates xml, re-reads the xml and then compares the sql of both to
 * verify the serialization / deserialization code works.
 */
@Test
public void testXmlReadingWriting() throws Exception {
  LogicalModel model = getDefaultModel();
  Domain domain = new Domain();
  domain.setId( "test_domain" );
  domain.getLogicalModels().add( model );
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" ); //$NON-NLS-1$
  LogicalColumn bce2 = model.findLogicalColumn( "bce2" ); //$NON-NLS-1$
  Category mainCat = model.findCategory( "cat_01" );
  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$
  Query myTest = new Query( domain, model );

  myTest.getSelections().add( new AliasedSelection( mainCat, bce2, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( mainCat, bc1, null, null ) );
  myTest.getSelections().add( new AliasedSelection( mainCat, bce2, null, null ) );

  // myTest.getOrders().add(new Order((new AliasedSelection(null, bc1, null, null), true);
  // myTest.getOrders().add(new Order((new AliasedSelection(null, bce2, null, "alias1"), true);

  myTest.getConstraints().add( new Constraint( CombinationType.OR, "[alias1.bce2] > 10" ) );

  // System.out.println(myTest.getXML().replaceAll(">", ">\n"));
  AdvancedQueryXmlHelper xmlhelper = new AdvancedQueryXmlHelper();
  String xml = xmlhelper.toXML( myTest );
  InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
  repo.storeDomain( domain, false );
  Query myReadTest = xmlhelper.fromXML( repo, xml );

  Assert.assertEquals( new AdvancedSqlGenerator().generateSql( myTest, "en_US", null, databaseMeta ).getQuery(),
      new AdvancedSqlGenerator().generateSql( myReadTest, "en_US", null, databaseMeta ).getQuery() );

  xml =
      "<mql><domain_type>relational</domain_type><domain_id>test_domain</domain_id>"
          + "<model_id>model_01</model_id><model_name>Model 1</model_name>"
          + "<options><disable_distinct>false</disable_distinct></options>"
          + "<selections><selection><view>cat_01</view><column>bc1</column></selection>"
          + "<selection><alias>Alias1</alias><view>cat_01</view><column>bc1</column></selection></selections>"
          + "<constraints>   <constraint><operator/> <condition>[cat_01.bc1] =\"1539006\"</condition> </constraint> </constraints></mql>";
  Query myReadTest2 = xmlhelper.fromXML( repo, xml );

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT " + "   bt1.pc1 AS COL0," + "   bt1_Alias1.pc1 AS COL1 "
      + "FROM " + "   pt1 bt1," + "   pt1 bt1_Alias1 " + "WHERE" + "   ((bt1.pc1 = '1539006'))",
      new AdvancedSqlGenerator().generateSql( myReadTest2, "en_US", null, databaseMeta ).getQuery() );

  xml =
      "<mql>" + "  <domain_type>relational</domain_type>" + "  <domain_id>test_domain</domain_id>"
          + "  <model_id>model_01</model_id>" + "  <model_name>Model 1</model_name>" + "  <options>"
          + "    <disable_distinct>false</disable_distinct>" + "  </options>" + "  <selections>"
          + "    <selection><view>cat_01</view><column>bc1</column></selection>"
          + "    <selection><view>cat_01</view><column>bc2</column></selection>"
          + "    <selection><view>cat_01</view><column>bc3</column></selection>"
          + "    <selection><formula>[cat_01.bc1] * [cat_01.bc2]</formula></selection>"
          + "    <selection><formula>[cat_01.bc1] / [cat_01.bc2]</formula></selection>"
          + "    <selection><formula>[cat_01.bc1] + [cat_01.bc2]</formula></selection>"
          + "    <selection><formula>[cat_01.bc1] - [cat_01.bc2]</formula></selection>" + "  </selections>"
          + "  <constraints>"
          + "    <constraint><operator/> <condition>[cat_01.bc1] =\"1539006\"</condition> </constraint> "
          + "  </constraints>" + "</mql>";

  Query myReadTest3 = xmlhelper.fromXML( repo, xml );

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT " + "  bt1.pc1 AS COL0," + "  bt2.pc2 AS COL1,"
      + "  bt3.pc3 AS COL2," + "  bt1.pc1*bt2.pc2 AS COL3," + "  bt1.pc1/bt2.pc2 AS COL4,"
      + "  bt1.pc1+bt2.pc2 AS COL5," + "  bt1.pc1-bt2.pc2 AS COL6 " + "FROM " + "  pt1 bt1," + "  pt2 bt2,"
      + "  pt3 bt3 " + "WHERE" + "  (bt1.pc1 = bt2.pc2)" + "  AND (bt3.pc3 = bt2.pc2)"
      + "  AND ((bt1.pc1 = '1539006'))", new AdvancedSqlGenerator().generateSql( myReadTest3, "en_US", null,
      databaseMeta ).getQuery() );

}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:74,代码来源:AdvancedQueryIT.java

示例13: testGroupBySQLGeneration

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testGroupBySQLGeneration() {
  try {

    LogicalModel model = TestHelper.buildDefaultModel();
    LogicalColumn bc1 = model.findLogicalColumn( "bc1" );
    bc1.setProperty( IPhysicalColumn.AGGREGATIONTYPE_PROPERTY, AggregationType.SUM );
    LogicalColumn bc2 = model.findLogicalColumn( "bc2" );
    LogicalColumn bce2 = model.findLogicalColumn( "bce2" );
    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 query = new Query( null, model );

    query.getSelections().add( new Selection( null, bc1, null ) );
    query.getSelections().add( new Selection( null, bc2, null ) );
    query.getSelections().add( new Selection( null, bce2, null ) );

    query.getConstraints().add( new Constraint( CombinationType.AND, "[bt1.bc1] > 25" ) ); //$NON-NLS-1$

    SqlGenerator generator = new SqlGenerator();

    MappedQuery mquery = generator.generateSql( query, "en_US", null, databaseMeta );
    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT \n" //$NON-NLS-1$
        + "          SUM(bt1.pc1) AS COL0\n" //$NON-NLS-1$
        + "         ,bt2.pc2 AS COL1\n" //$NON-NLS-1$
        + "         , bt2.pc2  * 2 AS COL2\n"//$NON-NLS-1$
        + "FROM \n" //$NON-NLS-1$
        + "          pt1 bt1\n" //$NON-NLS-1$
        + "         ,pt2 bt2\n" //$NON-NLS-1$
        + "WHERE \n" //$NON-NLS-1$
        + "          (\n" //$NON-NLS-1$
        + "             bt1.pc1 = bt2.pc2\n" //$NON-NLS-1$
        + "          )\n" //$NON-NLS-1$
        + "GROUP BY \n" //$NON-NLS-1$
        + "          bt2.pc2\n" //$NON-NLS-1$
        + "         , bt2.pc2  * 2\n" //$NON-NLS-1$
        + "HAVING \n" //$NON-NLS-1$
        + "          (\n" //$NON-NLS-1$
        + "              SUM(bt1.pc1)  > 25\n" //$NON-NLS-1$
        + "          )\n", //$NON-NLS-1$
        mquery.getQuery() );
    Map map = mquery.getMap();
    Assert.assertNotNull( map );
    Assert.assertEquals( map.size(), 3 );
    Assert.assertEquals( map.get( "COL0" ), "bc1" ); //$NON-NLS-1$ //$NON-NLS-2$
    Assert.assertEquals( map.get( "COL1" ), "bc2" ); //$NON-NLS-1$ //$NON-NLS-2$
    Assert.assertEquals( map.get( "COL2" ), "bce2" ); //$NON-NLS-1$ //$NON-NLS-2$

    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT \n" //$NON-NLS-1$
        + "          SUM(bt1.pc1) AS bc1\n" //$NON-NLS-1$
        + "         ,bt2.pc2 AS bc2\n" //$NON-NLS-1$
        + "         , bt2.pc2  * 2 AS bce2\n"//$NON-NLS-1$        
        + "FROM \n" //$NON-NLS-1$
        + "          pt1 bt1\n" //$NON-NLS-1$
        + "         ,pt2 bt2\n" //$NON-NLS-1$
        + "WHERE \n" //$NON-NLS-1$
        + "          (\n" //$NON-NLS-1$
        + "             bt1.pc1 = bt2.pc2\n" //$NON-NLS-1$
        + "          )\n" //$NON-NLS-1$
        + "GROUP BY \n" //$NON-NLS-1$
        + "          bt2.pc2\n" //$NON-NLS-1$
        + "         , bt2.pc2  * 2\n" //$NON-NLS-1$
        + "HAVING \n" //$NON-NLS-1$
        + "          (\n" //$NON-NLS-1$        
        + "              SUM(bt1.pc1)  > 25\n" //$NON-NLS-1$
        + "          )\n", //$NON-NLS-1$
        mquery.getDisplayQuery() );

    MemoryMetaData mmd = new MemoryMetaData( new Object[][] { { "COL0", "COL1" } }, //$NON-NLS-1$  //$NON-NLS-2$
        null );

    QueryModelMetaData emd = (QueryModelMetaData) mquery.generateMetadata( mmd );

    Assert.assertEquals( "pc1", emd.getAttribute( 0, 0, SqlPhysicalColumn.TARGET_COLUMN ).toString() ); //$NON-NLS-1$  //$NON-NLS-2$

  } catch ( Exception e ) {
    e.printStackTrace();
    Assert.fail();
  }
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:80,代码来源:SqlGeneratorIT.java

示例14: testFirstConstraintNOT

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testFirstConstraintNOT() {
  try {

    LogicalModel model = TestHelper.buildDefaultModel();
    LogicalColumn bc1 = model.findLogicalColumn( "bc1" );
    LogicalColumn bc2 = model.findLogicalColumn( "bc2" );
    DatabaseMeta databaseMeta = new DatabaseMeta( "", "HYPERSONIC", "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$
    databaseMeta.setQuoteAllFields( true );
    Query query = new Query( null, model );

    query.getSelections().add( new Selection( null, bc1, null ) );
    query.getSelections().add( new Selection( null, bc2, null ) );

    query.getConstraints().add( new Constraint( CombinationType.AND_NOT, "[bt1.bc1] > 1" ) ); //$NON-NLS-1$
    query.getConstraints().add( new Constraint( CombinationType.AND_NOT, "[bt1.bc1] < 1" ) ); //$NON-NLS-1$

    SqlGenerator generator = new SqlGenerator();

    MappedQuery mquery = generator.generateSql( query, "en_US", null, databaseMeta );

    // TestHelper.printOutJava(mquery.getQuery());

    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          \"bt1\".\"pc1\" AS \"COL0\"\n"
        + "         ,\"bt2\".\"pc2\" AS \"COL1\"\n" + "FROM \n" + "          \"pt1\" \"bt1\"\n"
        + "         ,\"pt2\" \"bt2\"\n" + "WHERE \n" + "          ( \"bt1\".\"pc1\" = \"bt2\".\"pc2\" )\n"
        + "      AND \n" + "        (\n" + "      NOT (\n" + "              \"bt1\".\"pc1\"  > 1\n" + "          )\n"
        + "      AND NOT (\n" + "              \"bt1\".\"pc1\"  < 1\n" + "          )\n" + "        )\n", mquery
        .getQuery() );

    query = new Query( null, model );

    query.getSelections().add( new Selection( null, bc1, null ) );
    query.getSelections().add( new Selection( null, bc2, null ) );

    query.getConstraints().add( new Constraint( CombinationType.OR_NOT, "[bt1.bc1] > 1" ) ); //$NON-NLS-1$
    query.getConstraints().add( new Constraint( CombinationType.OR_NOT, "[bt1.bc1] < 1" ) ); //$NON-NLS-1$

    mquery = generator.generateSql( query, "en_US", null, databaseMeta );

    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          \"bt1\".\"pc1\" AS \"COL0\"\n"
        + "         ,\"bt2\".\"pc2\" AS \"COL1\"\n" + "FROM \n" + "          \"pt1\" \"bt1\"\n"
        + "         ,\"pt2\" \"bt2\"\n" + "WHERE \n" + "          ( \"bt1\".\"pc1\" = \"bt2\".\"pc2\" )\n"
        + "      AND \n" + "        (\n" + "      NOT (\n" + "              \"bt1\".\"pc1\"  > 1\n" + "          )\n"
        + "      OR NOT (\n" + "              \"bt1\".\"pc1\"  < 1\n" + "          )\n" + "        )\n", mquery
        .getQuery() );

  } catch ( Exception e ) {
    e.printStackTrace();
    Assert.fail();
  }
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:53,代码来源:SqlGeneratorIT.java

示例15: testParameterSqlGeneration

import org.pentaho.metadata.model.LogicalModel; //导入方法依赖的package包/类
@Test
public void testParameterSqlGeneration() {
  try {

    LogicalModel model = TestHelper.buildDefaultModel();
    LogicalColumn bc1 = model.findLogicalColumn( "bc1" );
    LogicalColumn bc2 = model.findLogicalColumn( "bc2" );
    LogicalColumn bce2 = model.findLogicalColumn( "bce2" );
    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 query = new Query( null, model );

    query.getParameters().add( new Parameter( "test1", DataType.BOOLEAN, true ) );
    query.getParameters().add( new Parameter( "test2", DataType.NUMERIC, 1.2 ) );
    query.getParameters().add( new Parameter( "test3", DataType.STRING, "value" ) );

    query.getSelections().add( new Selection( null, bc1, null ) );
    query.getSelections().add( new Selection( null, bc2, null ) );

    query.getConstraints().add( new Constraint( CombinationType.AND, "[param:test1]" ) ); //$NON-NLS-1$
    query.getConstraints().add( new Constraint( CombinationType.AND, "[bt1.bc1] > [param:test2]" ) ); //$NON-NLS-1$
    query.getConstraints().add( new Constraint( CombinationType.AND, "[param:test3] = [bt2.bc2]" ) ); //$NON-NLS-1$

    SqlGenerator generator = new SqlGenerator();

    MappedQuery mquery = generator.generateSql( query, "en_US", null, databaseMeta, null, false );
    // TestHelper.printOutJava(mquery.getQuery());
    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          bt1.pc1 AS COL0\n"
        + "         ,bt2.pc2 AS COL1\n" + "FROM \n" + "          pt1 bt1\n" + "         ,pt2 bt2\n" + "WHERE \n"
        + "          ( bt1.pc1 = bt2.pc2 )\n" + "      AND \n" + "        (\n" + "          (\n"
        + "             1=1\n" + "          )\n" + "      AND (\n" + "              bt1.pc1  > 1.2\n"
        + "          )\n" + "      AND (\n" + "             'value' =  bt2.pc2 \n" + "          )\n" + "        )\n",
        mquery.getQuery() );

    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put( "test1", false );
    parameters.put( "test2", 2.1 );
    parameters.put( "test3", "eulav" );

    mquery = generator.generateSql( query, "en_US", null, databaseMeta, parameters, false );
    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          bt1.pc1 AS COL0\n"
        + "         ,bt2.pc2 AS COL1\n" + "FROM \n" + "          pt1 bt1\n" + "         ,pt2 bt2\n" + "WHERE \n"
        + "          ( bt1.pc1 = bt2.pc2 )\n" + "      AND \n" + "        (\n" + "          (\n"
        + "             1=0\n" + "          )\n" + "      AND (\n" + "              bt1.pc1  > 2.1\n"
        + "          )\n" + "      AND (\n" + "             'eulav' =  bt2.pc2 \n" + "          )\n" + "        )\n",
        mquery.getQuery() );

    Assert.assertNull( mquery.getParamList() );

    mquery = generator.generateSql( query, "en_US", null, databaseMeta, parameters, true );
    // TestHelper.printOutJava(mquery.getQuery());
    TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          bt1.pc1 AS COL0\n"
        + "         ,bt2.pc2 AS COL1\n" + "FROM \n" + "          pt1 bt1\n" + "         ,pt2 bt2\n" + "WHERE \n"
        + "          ( bt1.pc1 = bt2.pc2 )\n" + "      AND \n" + "        (\n" + "          (\n" + "             ?\n"
        + "          )\n" + "      AND (\n" + "              bt1.pc1  > ?\n" + "          )\n" + "      AND (\n"
        + "             ? =  bt2.pc2 \n" + "          )\n" + "        )\n", mquery.getQuery() );
    Assert.assertNotNull( mquery.getParamList() );
    Assert.assertEquals( 3, mquery.getParamList().size() );
    Assert.assertEquals( "test1", mquery.getParamList().get( 0 ) );
    Assert.assertEquals( "test2", mquery.getParamList().get( 1 ) );
    Assert.assertEquals( "test3", mquery.getParamList().get( 2 ) );

  } catch ( Exception e ) {
    e.printStackTrace();
    Assert.fail();
  }
}
 
开发者ID:pentaho,项目名称:pentaho-metadata,代码行数:67,代码来源:SqlGeneratorIT.java


注:本文中的org.pentaho.metadata.model.LogicalModel.findLogicalColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。