org.pentaho.aggdes.model.Parameter Java Examples

The following examples show how to use org.pentaho.aggdes.model.Parameter. 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: AbstractMondrianSchemaProvider.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
public Schema loadSchema(String cubeName) throws AggDesignerException{
  boolean validationHasErrors = doValidation(cubeName);
  if (validationHasErrors && !continueOnValidationErrors) {
    return null;
  }
  
  try {
    DatabaseMeta dbMeta = connectionModel.getDatabaseMeta();
    final String mondrianConnectionUrl = MessageFormat.format(
        "Provider={0};Jdbc={1};JdbcUser={2};JdbcPassword={3};Catalog={4};JdbcDrivers={5}", "Mondrian", dbMeta.getURL(), dbMeta
            .getUsername(), dbMeta.getPassword(), "file:" + getMondrianSchemaFilename(), 
            dbMeta.getDriverClass());
    
    Map<Parameter, Object> parameterValues = new HashMap<Parameter, Object>();

    parameterValues.put(mondrianSchemaLoader.getParameters().get(0), mondrianConnectionUrl);
    parameterValues.put(mondrianSchemaLoader.getParameters().get(1), cubeName);

    Schema newSchema = mondrianSchemaLoader.createSchema(parameterValues);
    return newSchema;
  } catch(KettleDatabaseException e){
    throw new AggDesignerException("Error loading Schema from Mondrian file",e);
  }
}
 
Example #2
Source File: MondrianSchemaLoaderTestIT.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
public void testMondrianStatisticsProvider() {
  MondrianSchemaLoader loader = new MondrianSchemaLoader();
  Map<Parameter, Object> parameterValues = new HashMap<>();
  parameterValues.put( loader.getParameters().get( 0 ), connectString );
  parameterValues.put( loader.getParameters().get( 1 ), "Sales" );
  Schema schema = loader.createSchema( parameterValues );
  StatisticsProvider statsProvider = schema.getStatisticsProvider();
  assertNotNull( statsProvider );

  assertEquals( statsProvider.getFactRowCount(), 86837.0 );

  List<Attribute> attributes = new ArrayList<>();
  attributes.add( schema.getAttributes().get( 0 ) );

  // spot check that these methods return a meaningful value

  assertEquals( statsProvider.getRowCount( attributes ), 3.0 );
  assertEquals( statsProvider.getLoadTime( attributes ), 3.8555688E7 );
  assertEquals( statsProvider.getSpace( attributes ), 20.0 );
}
 
Example #3
Source File: ValidationMondrianSchemaLoaderTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  // make a copy of the FoodMart.xml (from the classpath) so that it can be referenced as an absolute file: url
  tmpFile = File.createTempFile("FoodMart", ".xml");
  FileOutputStream out = new FileOutputStream(tmpFile);

  InputStream in = this.getClass().getResourceAsStream("/FoodMart.xml");

  IOUtils.copy(in, out);
  IOUtils.closeQuietly(in);
  IOUtils.closeQuietly(out);

  parameterValues = new HashMap<Parameter, Object>();
  // 2 required parameters
  parameterValues.put(MondrianSchemaLoaderParameter.cube, "Sales");
  parameterValues.put(MondrianSchemaLoaderParameter.connectString,
      "Provider=Mondrian;JdbcDrivers=org.hsqldb.jdbcDriver;Jdbc=jdbc:hsqldb:mem:test;JdbcUser=sa;JdbcPassword=;Catalog=file:"
          + tmpFile.getAbsolutePath());
  ValidationMondrianSchemaLoaderTest.myValidatorCalled = false;
  ValidationMondrianSchemaLoaderTest.myValidator2Called = false;
}
 
Example #4
Source File: SchemaLoaderStub.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
public List<Parameter> getParameters() {
  Parameter param = new Parameter() {

    public String getDescription() {
      return "Description";
    }

    public String getName() {
      return "cube";
    }

    public Type getType() {
      return Type.STRING;
    }

    public boolean isRequired() {
      return false;
    }
    
  };
  List<Parameter> list = new ArrayList<Parameter>();
  list.add(param);
  return list;
}
 
Example #5
Source File: AlgorithmStub.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
public List<Parameter> getParameters() {
  Parameter param = new Parameter() {

    public String getDescription() {
      return "Description";
    }

    public String getName() {
      return "execTime";
    }

    public Type getType() {
      return Type.INTEGER;
    }

    public boolean isRequired() {
      return false;
    }
    
  };
  List<Parameter> list = new ArrayList<Parameter>();
  list.add(param);
  return list;
}
 
Example #6
Source File: AlgorithmStub.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
public Result run(Schema schema, Map<Parameter, Object> parameterValues, Progress progress) {
  canceled = false;
  int i = 0;
  while (!canceled && i < 3) {
    try {
      System.out.println("algorithm running");
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    } finally {
      i++;
    }
  }
  if (canceled) {
    System.out.println("algorithm canceled");
    return null;
  } else {
    System.out.println("algorithm ended normally");
    return new ResultStub();
  }
  
}
 
Example #7
Source File: AlgorithmRunner.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
public void start(final Map<String, String> algorithmRawParams, final Callback callback) {
  // gen the params
  final Map<Parameter, Object> algorithmParams = ArgumentUtils.validateParameters(algorithm, algorithmRawParams);

  // Run the algorithm.
  final TextProgress progress = new TextProgress(pw);

  new Thread() {
    @Override
    public void run() {
      logger.debug("Calling algorithm run method with parameters: "+algorithmParams);
      result = algorithm.run(connectionModel.getSchema(), algorithmParams, progress);
      callback.algorithmDone();
    }
  }.start();

}
 
Example #8
Source File: AlgorithmImpl.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by the {@link #run} method, resets the 'canceled' flag and
 * sets the start time for timeout purposes.
 *
 * @param parameterValues Parameters
 * @param progress Progress callback
 */
protected void onStart(
    Map<Parameter, Object> parameterValues,
    Progress progress)
{
    this.progress = progress;
    this.canceled = false;
    final Integer integer =
        (Integer) parameterValues.get(ParameterEnum.timeLimitSeconds);
    if (integer == null) {
        this.timeoutMillis = Long.MAX_VALUE;
    } else {
        this.timeoutMillis =
            System.currentTimeMillis()
                + 1000L * integer;
    }
}
 
Example #9
Source File: Main.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prints usage.
 *
 * @param component Component; if not null, describes the parameters
 *   accepted by given component
 */
private void usage(Component component) {
    pw.println("Usage: java " + Main.class.getName());
    pw.println("  --help");
    pw.println("  --loaderClass <class>");
    pw.println("  [ --loaderParam <name> <value> ]...");
    pw.println("  --algorithmClass <class>");
    pw.println("  [ --algorithmParam <name> <value> ]...");
    pw.println("  --resultClass <class>");
    pw.println("  [ --resultParam <name> <value> ]...");

    if (component != null) {
        pw.println();
        pw.println("Parameters for component " + component.getName()
            + " are:");
        for (Parameter parameter : component.getParameters()) {
            String desc = "  " + parameter.getName()
                + " (" + parameter.getType()
                + (parameter.isRequired() ? ", required" : "")
                + ") " + parameter.getDescription();
            pw.println(desc);
        }
    }
}
 
Example #10
Source File: AlgorithmStub.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public List<CostBenefit> computeAggregateCosts(
  Schema schema,
  Map<Parameter, Object> parameterValues,
  List<Aggregate> aggregateList)
{
  return null;
}
 
Example #11
Source File: MondrianSchemaLoaderTestIT.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public void testInvalidCubeParameter() {
  try {
    MondrianSchemaLoader loader = new MondrianSchemaLoader();
    Map<Parameter, Object> parameterValues = new HashMap<>();
    parameterValues.put( loader.getParameters().get( 0 ), connectString );
    parameterValues.put( loader.getParameters().get( 1 ), "InvalidCube" );
    loader.createSchema( parameterValues );
    fail();
  } catch ( mondrian.olap.MondrianException e ) {
    assertEquals( e.getMessage(), "Mondrian Error:MDX cube 'InvalidCube' not found" );
  }
}
 
Example #12
Source File: MondrianSchemaLoaderTestIT.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public void testInvalidConnectStringParameter() {
  try {
    MondrianSchemaLoader loader = new MondrianSchemaLoader();
    Map<Parameter, Object> parameterValues = new HashMap<>();
    parameterValues.put( loader.getParameters().get( 0 ), "badconnstr" );
    loader.createSchema( parameterValues );
    fail();
  } catch ( mondrian.olap.MondrianException e ) {
    assertEquals(
      "Mondrian Error:Internal error: Connect string 'badconnstr=; Catalog='null'' must contain either 'Jdbc' or "
        + "'DataSource'",
      e.getMessage() );
  }
}
 
Example #13
Source File: TableGeneratorTestIT.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public void testResultHandlerImpl() {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream pw = new PrintStream( baos );
    PrintStream orig = System.out;
    System.setOut( pw );

    MondrianSchemaLoader loader = new MondrianSchemaLoader();
    Map<Parameter, Object> parameterValues = new HashMap<>();
    System.out.println( "CONN STR: " + connectString );
    parameterValues.put( loader.getParameters().get( 0 ), connectString );
    parameterValues.put( loader.getParameters().get( 1 ), "Sales" );
    Schema schema = loader.createSchema( parameterValues );

    TestResult result = new TestResult();
    TestAggregate aggregate = new TestAggregate();
    aggregate.setCandidateTableName( "candidate_01" );
    aggregate.addAttribute( schema.getAttributes().get( 3 ) ); // store name level
    aggregate.addAttribute( schema.getAttributes().get( 12 ) ); // product name level

    // add all measures
    for ( Measure measure : schema.getMeasures() ) {
      aggregate.addMeasure( measure );
    }

    result.addAggregate( aggregate );

    ResultHandlerImpl resultHandler = new ResultHandlerImpl();

    assertEquals( resultHandler.getName(), "ResultHandlerImpl" );

    assertEquals( resultHandler.getParameters().size(), 8 );

    assertEquals( resultHandler.getParameters().get( 0 ).isRequired(), false );
    assertEquals( resultHandler.getParameters().get( 0 ).getType(), Parameter.Type.BOOLEAN );
    assertEquals( resultHandler.getParameters().get( 0 ).getDescription(),
      "Whether to output CREATE TABLE statements." );
    assertEquals( resultHandler.getParameters().get( 0 ).getName(), "tables" );


    Map<Parameter, Object> params = new HashMap<>();
    params.put( resultHandler.getParameters().get( 0 ), true );
    params.put( resultHandler.getParameters().get( 4 ), true );
    params.put( resultHandler.getParameters().get( 6 ), true );

    // no output file params, write to system.out
    resultHandler.handle( params, schema, result );

    String results = baos.toString();

    // verify ddl, dml and schema output are available
    assertTrue( results.indexOf( "CREATE TABLE" ) >= 0 );
    assertTrue( results.indexOf( "INSERT INTO" ) >= 0 );
    assertTrue( results.indexOf( "<Schema" ) >= 0 );
    System.setOut( orig );

    File outputFile = new File( "resulthandlerimpl_output.txt" );
    if ( outputFile.exists() ) {
      outputFile.delete();
    }

    params.clear();
    params.put( resultHandler.getParameters().get( 0 ), true );
    params.put( resultHandler.getParameters().get( 1 ), "resulthandlerimpl_output.txt" );

    // output file param first element, write to file
    resultHandler.handle( params, schema, result );

    assertTrue( outputFile.exists() );
  }
 
Example #14
Source File: AlgorithmImplTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public void onStart(
    Map<Parameter, Object> parameterValues,
    Progress progress)
{
  super.onStart(parameterValues, progress);
}
 
Example #15
Source File: AlgorithmImplTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public Result run(Schema schema, Map<Parameter, Object> parameterValues, Progress progress) {
  return null;
}
 
Example #16
Source File: AlgorithmImplTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<CostBenefit> computeAggregateCosts(Schema schema,
    Map<Parameter, Object> parameterValues, List<Aggregate> aggregateList) {
  computeAggCostsCalled = true;
  return new ArrayList<CostBenefit>();
}
 
Example #17
Source File: MondrianSchemaLoaderTestIT.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public void testMondrianSchemaModel() throws SQLException {
  MondrianSchemaLoader loader = new MondrianSchemaLoader();
  Map<Parameter, Object> parameterValues = new HashMap<>();
  parameterValues.put( loader.getParameters().get( 0 ), connectString );
  parameterValues.put( loader.getParameters().get( 1 ), "Sales" );
  Schema schema = loader.createSchema( parameterValues );

  assertTrue( schema instanceof MondrianSchema );
  MondrianSchema mondrianSchema = (MondrianSchema) schema;

  assertNotNull( mondrianSchema.getDatabaseMetaData() );

  // spot check measures, attributes, and tables
  assertEquals( 7, schema.getMeasures().size() );
  assertEquals( "sales_fact_1997.Unit Sales", schema.getMeasures().get( 0 ).getLabel() );

  // spot check the fact_count measure
  assertEquals( "sales_fact_1997.fact_count", schema.getMeasures().get( 6 ).getLabel() );

  assertEquals( schema.getMeasures().get( 0 ).isDistinct(), false );
  // check that the fact table is the first table in table list
  assertEquals( schema.getMeasures().get( 0 ).getTable(), schema.getTables().get( 0 ) );
  assertEquals( schema.getMeasures().get( 0 ).estimateSpace(), 4.0 );
  assertEquals( schema.getMeasures().get( 0 ).getAncestorAttributes(), null );

  assertEquals( 8, schema.getTables().size() );
  assertEquals( "sales_fact_1997", schema.getTables().get( 0 ).getLabel() );
  assertEquals( schema.getTables().get( 1 ).getParent(), schema.getTables().get( 0 ) );

  assertTrue( schema.getTables().get( 0 ) instanceof MondrianTable );
  assertNotNull( ( (MondrianTable) schema.getTables().get( 0 ) ).getStarTable() );

  assertEquals( 27, schema.getAttributes().size() );
  assertEquals( "[store].[Store Country]", schema.getAttributes().get( 0 ).getLabel() );
  assertEquals( schema.getAttributes().get( 0 ).getTable(), schema.getTables().get( 1 ) );

  assertTrue( schema.getAttributes().get( 0 ) instanceof MondrianAttribute );
  assertEquals( ( (MondrianAttribute) schema.getAttributes().get( 0 ) ).getDistinctValueCount(), 3.0 );
  assertEquals( ( (MondrianAttribute) schema.getAttributes().get( 0 ) ).estimateSpace(), 20.0 );

  // spot check a couple of attribute ancestor lists
  assertEquals( schema.getAttributes().get( 3 ).getAncestorAttributes().size(), 3 );
  assertEquals( schema.getAttributes().get( 22 ).getAncestorAttributes().get( 0 ).getLabel(),
    "[customer].[Country]" );

  // spot check level mapping to attributes

  assertEquals( schema.getDimensions().get( 1 ).getName(), "Store Size in SQFT" );

  assertEquals( schema.getDimensions().get( 0 ).getHierarchies().get( 0 ).getName(), "Store" );

  assertEquals( schema.getDimensions().get( 2 ).getHierarchies().get( 0 ).getLevels().get( 1 ).getName(),
    "Store Type" );

  // verifies quarter is the expected attribute in the level
  assertEquals( schema.getAttributes().get( 7 ),
    schema.getDimensions().get( 3 ).getHierarchies().get( 0 ).getLevels().get( 1 ).getAttribute() );
}
 
Example #18
Source File: MondrianSchemaLoaderTestIT.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public void testFoodmartLoading() {
  MondrianSchemaLoader loader = new MondrianSchemaLoader();
  Map<Parameter, Object> parameterValues = new HashMap<>();
  parameterValues.put( loader.getParameters().get( 0 ), connectString );
  parameterValues.put( loader.getParameters().get( 1 ), "Sales" );
}
 
Example #19
Source File: AggDesignerMainTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<Parameter> getParameters() {
  return parameters;
}
 
Example #20
Source File: AggDesignerMainTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public ComponentStub() {
  Parameter string = new Parameter() {
    public String getDescription() {
      return "Description";
    }
    public String getName() {
      return "string";
    }
    public Type getType() {
      return Type.STRING;
    }
    public boolean isRequired() {
      return false;
    }
  };
  Parameter integer = new Parameter() {
    public String getDescription() {
      return "Description";
    }
    public String getName() {
      return "integer";
    }
    public Type getType() {
      return Type.INTEGER;
    }
    public boolean isRequired() {
      return false;
    }
  };
  Parameter doub = new Parameter() {
    public String getDescription() {
      return "Description";
    }
    public String getName() {
      return "double";
    }
    public Type getType() {
      return Type.DOUBLE;
    }
    public boolean isRequired() {
      return false;
    }
  };
  Parameter bool = new Parameter() {
    public String getDescription() {
      return "Description";
    }
    public String getName() {
      return "boolean";
    }
    public Type getType() {
      return Type.BOOLEAN;
    }
    public boolean isRequired() {
      return false;
    }
  };
  List<Parameter> list = new ArrayList<Parameter>();
  list.add(string);
  list.add(integer);
  list.add(doub);
  list.add(bool);
  parameters = list;
}
 
Example #21
Source File: AggDesignerMainTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<Parameter> getParameters() {
  return Collections.EMPTY_LIST;
}
 
Example #22
Source File: ResultHandlerStub.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<Parameter> getParameters() {
  return Collections.emptyList();
}
 
Example #23
Source File: AlgorithmImpl.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<Parameter> getParameters() {
    return parameterList;
}
 
Example #24
Source File: SchemaLoaderStub.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<ValidationMessage> validateSchema(Map<Parameter, Object> parameterValues) {
  return Collections.emptyList();
}
 
Example #25
Source File: SchemaLoaderStub.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public Schema createSchema(Map<Parameter, Object> parameterValues) {
  return new SchemaStub();
}
 
Example #26
Source File: ResultHandlerImpl.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<Parameter> getParameters() {
    return parameterList;
}
 
Example #27
Source File: MondrianSchemaLoader.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<Parameter> getParameters() {
  return Arrays.asList(
    (Parameter[]) MondrianSchemaLoaderParameter.values() );
}
 
Example #28
Source File: MondrianSchemaLoader.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<ValidationMessage> validateSchema( Map<Parameter, Object> parameterValues ) {
  String connectString =
    (String) parameterValues.get(
      MondrianSchemaLoaderParameter.connectString );
  String cubeName =
    (String) parameterValues.get(
      MondrianSchemaLoaderParameter.cube );

  PropertyList propertyList = Util.parseConnectString( connectString );

  String jdbcDrivers = propertyList.get( "JdbcDrivers" );
  if ( StringUtils.isBlank( jdbcDrivers ) ) {
    throw new RuntimeException( "missing 'JdbcDrivers' in connect string" );
  }

  Boolean integratedSecurity = Boolean.parseBoolean( propertyList.get( "integratedSecurity" ) );

  String jdbc = getJdbcConnectionString( propertyList, integratedSecurity );
  if ( StringUtils.isBlank( jdbcDrivers ) ) {
    throw new RuntimeException( "missing 'Jdbc' in connect string" );
  }

  String catalog = propertyList.get( "Catalog" );
  if ( StringUtils.isBlank( jdbcDrivers ) ) {
    throw new RuntimeException( "missing 'Catalog' in connect string" );
  }

  String jdbcUser = propertyList.get( "JdbcUser" );

  String jdbcPassword = propertyList.get( "JdbcPassword" );

  List<ValidationMessage> messages = new ArrayList<ValidationMessage>();

  try {
    List<MondrianSchemaValidator> validators = loadValidators( parameterValues );

    Class.forName( jdbcDrivers ); //$NON-NLS-1$

    java.sql.Connection conn;

    if ( integratedSecurity ) {
      conn = java.sql.DriverManager.getConnection( jdbc );
    } else {
      conn = java.sql.DriverManager.getConnection( jdbc, jdbcUser, jdbcPassword );
    }

    messages = ValidationHelper.validateCube( catalog, cubeName, conn, validators ); //$NON-NLS-1$

    conn.close();
  } catch ( Exception e ) {
    if ( logger.isErrorEnabled() ) {
      logger.error( "an exception occurred", e );
    }
    ValidationMessage msg =
      new ValidationMessage( ValidationMessage.Type.ERROR, e.getClass().getName() + ": " + e.getLocalizedMessage() );
    messages.add( msg );
  }
  return messages;
}
 
Example #29
Source File: AggDesignerMainTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 2 votes vote down vote up
public void handle(Map<Parameter, Object> parameterValues, Schema schema, Result result) {
  System.out.println("ResultHandlerStub handle called");
  
}
 
Example #30
Source File: ResultHandlerStub.java    From pentaho-aggdesigner with GNU General Public License v2.0 2 votes vote down vote up
public void handle(Map<Parameter, Object> parameterValues, Schema schema, Result result) {

  }