Search in sources :

Example 6 with Column

use of org.apache.phoenix.pherf.configuration.Column in project phoenix by apache.

the class RuleGeneratorTest method testSequentialDataSequence.

@Test
public void testSequentialDataSequence() throws Exception {
    XMLConfigParser parser = new XMLConfigParser(matcherScenario);
    DataModel model = parser.getDataModels().get(0);
    WriteWorkload loader = new WriteWorkload(parser);
    RulesApplier rulesApplier = loader.getRulesApplier();
    Column targetColumn = null;
    for (Column column : model.getDataMappingColumns()) {
        DataSequence sequence = column.getDataSequence();
        if (sequence == DataSequence.SEQUENTIAL) {
            targetColumn = column;
            break;
        }
    }
    assertNotNull("Could not find a DataSequence.SEQENTIAL rule.", targetColumn);
    assertMultiThreadedIncrementValue(targetColumn, rulesApplier);
}
Also used : RulesApplier(org.apache.phoenix.pherf.rules.RulesApplier) Column(org.apache.phoenix.pherf.configuration.Column) DataModel(org.apache.phoenix.pherf.configuration.DataModel) WriteWorkload(org.apache.phoenix.pherf.workload.WriteWorkload) XMLConfigParser(org.apache.phoenix.pherf.configuration.XMLConfigParser) DataSequence(org.apache.phoenix.pherf.configuration.DataSequence) Test(org.junit.Test)

Example 7 with Column

use of org.apache.phoenix.pherf.configuration.Column in project phoenix by apache.

the class WriteWorkload method buildStatement.

private PreparedStatement buildStatement(Scenario scenario, List<Column> columns, PreparedStatement statement, SimpleDateFormat simpleDateFormat) throws Exception {
    int count = 1;
    for (Column column : columns) {
        DataValue dataValue = getRulesApplier().getDataForRule(scenario, column);
        switch(column.getType()) {
            case VARCHAR:
                if (dataValue.getValue().equals("")) {
                    statement.setNull(count, Types.VARCHAR);
                } else {
                    statement.setString(count, dataValue.getValue());
                }
                break;
            case CHAR:
                if (dataValue.getValue().equals("")) {
                    statement.setNull(count, Types.CHAR);
                } else {
                    statement.setString(count, dataValue.getValue());
                }
                break;
            case DECIMAL:
                if (dataValue.getValue().equals("")) {
                    statement.setNull(count, Types.DECIMAL);
                } else {
                    statement.setBigDecimal(count, new BigDecimal(dataValue.getValue()));
                }
                break;
            case INTEGER:
                if (dataValue.getValue().equals("")) {
                    statement.setNull(count, Types.INTEGER);
                } else {
                    statement.setInt(count, Integer.parseInt(dataValue.getValue()));
                }
                break;
            case DATE:
                if (dataValue.getValue().equals("")) {
                    statement.setNull(count, Types.DATE);
                } else {
                    Date date = new java.sql.Date(simpleDateFormat.parse(dataValue.getValue()).getTime());
                    statement.setDate(count, date);
                }
                break;
            default:
                break;
        }
        count++;
    }
    return statement;
}
Also used : Column(org.apache.phoenix.pherf.configuration.Column) DataValue(org.apache.phoenix.pherf.rules.DataValue) BigDecimal(java.math.BigDecimal) Date(java.sql.Date)

Example 8 with Column

use of org.apache.phoenix.pherf.configuration.Column in project phoenix by apache.

the class RuleGeneratorTest method testValueListRule.

@Test
public void testValueListRule() throws Exception {
    List<String> expectedValues = new ArrayList();
    expectedValues.add("aAAyYhnNbBs9kWk");
    expectedValues.add("bBByYhnNbBs9kWu");
    expectedValues.add("cCCyYhnNbBs9kWr");
    XMLConfigParser parser = new XMLConfigParser(matcherScenario);
    WriteWorkload loader = new WriteWorkload(parser);
    RulesApplier rulesApplier = loader.getRulesApplier();
    Scenario scenario = parser.getScenarios().get(0);
    Column simPhxCol = new Column();
    simPhxCol.setName("PARENT_ID");
    simPhxCol.setType(DataTypeMapping.CHAR);
    // Run this 10 times gives a reasonable chance that all the values will appear at least once
    for (int i = 0; i < 10; i++) {
        DataValue value = rulesApplier.getDataForRule(scenario, simPhxCol);
        assertTrue("Got a value not in the list for the rule. :" + value.getValue(), expectedValues.contains(value.getValue()));
    }
}
Also used : RulesApplier(org.apache.phoenix.pherf.rules.RulesApplier) Column(org.apache.phoenix.pherf.configuration.Column) DataValue(org.apache.phoenix.pherf.rules.DataValue) WriteWorkload(org.apache.phoenix.pherf.workload.WriteWorkload) ArrayList(java.util.ArrayList) XMLConfigParser(org.apache.phoenix.pherf.configuration.XMLConfigParser) Scenario(org.apache.phoenix.pherf.configuration.Scenario) Test(org.junit.Test)

Example 9 with Column

use of org.apache.phoenix.pherf.configuration.Column in project phoenix by apache.

the class RuleGeneratorTest method testRuleOverrides.

@Test
public void testRuleOverrides() throws Exception {
    XMLConfigParser parser = new XMLConfigParser(matcherScenario);
    WriteWorkload loader = new WriteWorkload(parser);
    RulesApplier rulesApplier = loader.getRulesApplier();
    Scenario scenario = parser.getScenarios().get(0);
    // We should be able to find the correct rule based only on Type and Name combination
    // Test CHAR
    Column simPhxCol = new Column();
    simPhxCol.setName("OTHER_ID");
    simPhxCol.setType(DataTypeMapping.CHAR);
    // Get the rule we expect to match
    Column rule = rulesApplier.getRule(simPhxCol);
    assertEquals("Did not find the correct rule.", rule.getName(), simPhxCol.getName());
    assertEquals("Did not find the matching rule type.", rule.getType(), simPhxCol.getType());
    assertEquals("Rule contains incorrect length.", rule.getLength(), 8);
    assertEquals("Rule contains incorrect prefix.", rule.getPrefix(), "z0Oxx00");
    DataValue value = rulesApplier.getDataForRule(scenario, simPhxCol);
    assertEquals("Value returned does not match rule.", value.getValue().length(), 8);
    // Test VARCHAR with RANDOM and prefix
    simPhxCol.setName("OLDVAL_STRING");
    simPhxCol.setType(DataTypeMapping.VARCHAR);
    // Get the rule we expect to match
    rule = rulesApplier.getRule(simPhxCol);
    assertEquals("Did not find the correct rule.", rule.getName(), simPhxCol.getName());
    assertEquals("Did not find the matching rule type.", rule.getType(), simPhxCol.getType());
    assertEquals("Rule contains incorrect length.", rule.getLength(), 10);
    assertEquals("Rule contains incorrect prefix.", rule.getPrefix(), "MYPRFX");
    value = rulesApplier.getDataForRule(scenario, simPhxCol);
    assertEquals("Value returned does not match rule.", value.getValue().length(), 10);
    assertTrue("Value returned start with prefix.", StringUtils.startsWith(value.getValue(), rule.getPrefix()));
}
Also used : RulesApplier(org.apache.phoenix.pherf.rules.RulesApplier) Column(org.apache.phoenix.pherf.configuration.Column) DataValue(org.apache.phoenix.pherf.rules.DataValue) WriteWorkload(org.apache.phoenix.pherf.workload.WriteWorkload) XMLConfigParser(org.apache.phoenix.pherf.configuration.XMLConfigParser) Scenario(org.apache.phoenix.pherf.configuration.Scenario) Test(org.junit.Test)

Example 10 with Column

use of org.apache.phoenix.pherf.configuration.Column in project phoenix by apache.

the class WriteWorkload method buildSql.

private String buildSql(final List<Column> columns, final String tableName) {
    StringBuilder builder = new StringBuilder();
    builder.append("upsert into ");
    builder.append(tableName);
    builder.append(" (");
    int count = 1;
    for (Column column : columns) {
        builder.append(column.getName());
        if (count < columns.size()) {
            builder.append(",");
        } else {
            builder.append(")");
        }
        count++;
    }
    builder.append(" VALUES (");
    for (int i = 0; i < columns.size(); i++) {
        if (i < columns.size() - 1) {
            builder.append("?,");
        } else {
            builder.append("?)");
        }
    }
    return builder.toString();
}
Also used : Column(org.apache.phoenix.pherf.configuration.Column)

Aggregations

Column (org.apache.phoenix.pherf.configuration.Column)12 Test (org.junit.Test)8 DataValue (org.apache.phoenix.pherf.rules.DataValue)7 RulesApplier (org.apache.phoenix.pherf.rules.RulesApplier)7 WriteWorkload (org.apache.phoenix.pherf.workload.WriteWorkload)7 XMLConfigParser (org.apache.phoenix.pherf.configuration.XMLConfigParser)6 DataModel (org.apache.phoenix.pherf.configuration.DataModel)5 ArrayList (java.util.ArrayList)4 Scenario (org.apache.phoenix.pherf.configuration.Scenario)4 SQLException (java.sql.SQLException)2 BigDecimal (java.math.BigDecimal)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Connection (java.sql.Connection)1 Date (java.sql.Date)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1 DataSequence (org.apache.phoenix.pherf.configuration.DataSequence)1 PherfException (org.apache.phoenix.pherf.exception.PherfException)1 SchemaReader (org.apache.phoenix.pherf.schema.SchemaReader)1