Search in sources :

Example 1 with DimensionalConfigurationSchema

use of org.apache.apex.malhar.lib.appdata.schemas.DimensionalConfigurationSchema in project apex-malhar by apache.

the class JDBCDimensionalOutputOperator method setup.

@Override
public void setup(Context.OperatorContext context) {
    super.setup(context);
    LOG.info("Done setting up super");
    aggregatorRegistry.setup();
    // Create prepared statements
    schema = new DimensionalConfigurationSchema(eventSchema, aggregatorRegistry);
    List<FieldsDescriptor> keyFDs = schema.getDimensionsDescriptorIDToKeyDescriptor();
    for (int ddID = 0; ddID < keyFDs.size(); ddID++) {
        LOG.info("ddID {}", ddID);
        FieldsDescriptor keyFD = keyFDs.get(ddID);
        Int2ObjectMap<FieldsDescriptor> aggIDToAggFD = schema.getDimensionsDescriptorIDToAggregatorIDToOutputAggregatorDescriptor().get(ddID);
        Map<Integer, PreparedStatement> aggIDToStatement = ddIDToAggIDToStatement.get(ddID);
        if (aggIDToStatement == null) {
            aggIDToStatement = Maps.newHashMap();
            ddIDToAggIDToStatement.put(ddID, aggIDToStatement);
        }
        for (Map.Entry<String, String> aggTable : tableNames.get(ddID).entrySet()) {
            int aggID = aggregatorRegistry.getIncrementalAggregatorNameToID().get(aggTable.getKey());
            LOG.info("aggID {}", aggID);
            FieldsDescriptor aggFD = aggIDToAggFD.get(aggID);
            List<String> keyNames = keyFD.getFieldList();
            keyNames.remove(DimensionsDescriptor.DIMENSION_TIME_BUCKET);
            LOG.info("List fields {}", keyNames);
            List<String> aggregateNames = aggFD.getFieldList();
            LOG.info("List fields {}", aggregateNames);
            String tableName = aggTable.getValue();
            String statementString = buildStatement(tableName, keyNames, aggregateNames);
            try {
                aggIDToStatement.put(aggID, store.getConnection().prepareStatement(statementString));
            } catch (SQLException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) FieldsDescriptor(org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor) DimensionalConfigurationSchema(org.apache.apex.malhar.lib.appdata.schemas.DimensionalConfigurationSchema) PreparedStatement(java.sql.PreparedStatement) Map(java.util.Map) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap)

Aggregations

Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 DimensionalConfigurationSchema (org.apache.apex.malhar.lib.appdata.schemas.DimensionalConfigurationSchema)1 FieldsDescriptor (org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor)1