Search in sources :

Example 1 with IndexSourceColNames

use of org.apache.phoenix.mapreduce.index.SourceTargetColumnNames.IndexSourceColNames in project phoenix by apache.

the class IndexScrutinyTableOutput method writeJobResults.

/**
 * Writes the results of the given jobs to the metadata table
 * @param conn connection to use
 * @param cmdLineArgs arguments the {@code IndexScrutinyTool} was run with
 * @param completedJobs completed MR jobs
 * @throws IOException
 * @throws SQLException
 */
public static void writeJobResults(Connection conn, String[] cmdLineArgs, List<Job> completedJobs) throws IOException, SQLException {
    PreparedStatement pStmt = conn.prepareStatement(UPSERT_METADATA_SQL);
    for (Job job : completedJobs) {
        Configuration conf = job.getConfiguration();
        String qDataTable = PhoenixConfigurationUtil.getScrutinyDataTableName(conf);
        final PTable pdataTable = PhoenixRuntime.getTable(conn, qDataTable);
        final String qIndexTable = PhoenixConfigurationUtil.getScrutinyIndexTableName(conf);
        final PTable pindexTable = PhoenixRuntime.getTable(conn, qIndexTable);
        SourceTable sourceTable = PhoenixConfigurationUtil.getScrutinySourceTable(conf);
        long scrutinyExecuteTime = PhoenixConfigurationUtil.getScrutinyExecuteTimestamp(conf);
        SourceTargetColumnNames columnNames = SourceTable.DATA_TABLE_SOURCE.equals(sourceTable) ? new DataSourceColNames(pdataTable, pindexTable) : new IndexSourceColNames(pdataTable, pindexTable);
        Counters counters = job.getCounters();
        int index = 1;
        pStmt.setString(index++, columnNames.getQualifiedSourceTableName());
        pStmt.setString(index++, columnNames.getQualifiedTargetTableName());
        pStmt.setLong(index++, scrutinyExecuteTime);
        pStmt.setString(index++, sourceTable.name());
        pStmt.setString(index++, Arrays.toString(cmdLineArgs));
        pStmt.setLong(index++, counters.findCounter(PhoenixJobCounters.INPUT_RECORDS).getValue());
        pStmt.setLong(index++, counters.findCounter(PhoenixJobCounters.FAILED_RECORDS).getValue());
        pStmt.setLong(index++, counters.findCounter(PhoenixScrutinyJobCounters.VALID_ROW_COUNT).getValue());
        pStmt.setLong(index++, counters.findCounter(PhoenixScrutinyJobCounters.INVALID_ROW_COUNT).getValue());
        pStmt.setLong(index++, counters.findCounter(PhoenixScrutinyJobCounters.BAD_COVERED_COL_VAL_COUNT).getValue());
        pStmt.setLong(index++, counters.findCounter(PhoenixScrutinyJobCounters.BATCHES_PROCESSED_COUNT).getValue());
        pStmt.setString(index++, Arrays.toString(columnNames.getSourceDynamicCols().toArray()));
        pStmt.setString(index++, Arrays.toString(columnNames.getTargetDynamicCols().toArray()));
        pStmt.setString(index++, getSqlQueryAllInvalidRows(conn, columnNames, scrutinyExecuteTime));
        pStmt.setString(index++, getSqlQueryMissingTargetRows(conn, columnNames, scrutinyExecuteTime));
        pStmt.setString(index++, getSqlQueryBadCoveredColVal(conn, columnNames, scrutinyExecuteTime));
        pStmt.addBatch();
    }
    pStmt.executeBatch();
    conn.commit();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) IndexSourceColNames(org.apache.phoenix.mapreduce.index.SourceTargetColumnNames.IndexSourceColNames) SourceTable(org.apache.phoenix.mapreduce.index.IndexScrutinyTool.SourceTable) PreparedStatement(java.sql.PreparedStatement) PhoenixJobCounters(org.apache.phoenix.mapreduce.PhoenixJobCounters) Counters(org.apache.hadoop.mapreduce.Counters) DataSourceColNames(org.apache.phoenix.mapreduce.index.SourceTargetColumnNames.DataSourceColNames) Job(org.apache.hadoop.mapreduce.Job) PTable(org.apache.phoenix.schema.PTable)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 Configuration (org.apache.hadoop.conf.Configuration)1 Counters (org.apache.hadoop.mapreduce.Counters)1 Job (org.apache.hadoop.mapreduce.Job)1 PhoenixJobCounters (org.apache.phoenix.mapreduce.PhoenixJobCounters)1 SourceTable (org.apache.phoenix.mapreduce.index.IndexScrutinyTool.SourceTable)1 DataSourceColNames (org.apache.phoenix.mapreduce.index.SourceTargetColumnNames.DataSourceColNames)1 IndexSourceColNames (org.apache.phoenix.mapreduce.index.SourceTargetColumnNames.IndexSourceColNames)1 PTable (org.apache.phoenix.schema.PTable)1