Search in sources :

Example 6 with Row

use of me.prettyprint.hector.api.beans.Row in project logprocessing by cloudian.

the class CDRDataAccess method deleteBeforeTS.

// Delete all entries before (and including) a particular hour timestamp.  
// For the hourly timeline, 
public void deleteBeforeTS(long hourStamp) {
    String sLastHour = m_sdfHourly.format(new Date(hourStamp));
    String strLastHourCompare = String.format("%013d", hourStamp);
    // those columns.
    try {
        boolean bMoreRows = true;
        String begRangeKey = "";
        // Handle HourlyTimeline and CDREntry CFs first
        while (bMoreRows) {
            List<Row<String, String, String>> rows = m_daoHourlyTimeline.getRangeSlice(begRangeKey, sLastHour, "", LIMIT, false);
            if (rows.size() > 0) {
                Row<String, String, String> lastRow = rows.get(rows.size() - 1);
                // Get start key for next range slice
                begRangeKey = lastRow.getKey();
                for (Row<String, String, String> row : rows) {
                    List<HColumn<String, String>> cols = row.getColumnSlice().getColumns();
                    for (HColumn<String, String> col : cols) {
                        String entryId = col.getValue();
                        // Delete individual CDR entry
                        m_daoCDREntry.delete(entryId, null, StringSerializer.get());
                    }
                    String hourKey = row.getKey();
                    // Delete entire row.
                    m_daoHourlyTimeline.delete(hourKey, null, StringSerializer.get());
                }
                if (rows.size() == 1) {
                    // this is the last row in the slice - data was already deleted.
                    bMoreRows = false;
                }
            } else {
                // Done operating on rows for HourlyTimeline
                bMoreRows = false;
            }
        }
        // Now take care of MSISDNTimeline
        bMoreRows = true;
        begRangeKey = "";
        while (bMoreRows) {
            List<Row<String, String, String>> rows = m_daoMSISDNTimeline.getRangeSlice(begRangeKey, "", "", LIMIT, false);
            if (rows.size() > 0) {
                Row<String, String, String> lastRow = rows.get(rows.size() - 1);
                // Get start key for next range slice
                begRangeKey = lastRow.getKey();
                for (Row<String, String, String> row : rows) {
                    List<HColumn<String, String>> cols = row.getColumnSlice().getColumns();
                    for (HColumn<String, String> col : cols) {
                        String colStamp = col.getName();
                        if (colStamp.compareTo(strLastHourCompare) < 0) {
                            // Lexicographic comparison - want to ignore the UUID portion of column name
                            // Delete MSISDNTimeline column
                            m_daoHourlyTimeline.delete(row.getKey(), colStamp, StringSerializer.get());
                        // TODO: Should we optimize to add all deletions for the row, and then execute??
                        }
                    }
                }
                if (rows.size() == 1) {
                    // this is the last row in the slice - data was already deleted.
                    bMoreRows = false;
                }
            } else {
                // Done operating on rows for MSISDNTimeline
                bMoreRows = false;
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }
}
Also used : HColumn(me.prettyprint.hector.api.beans.HColumn) Row(me.prettyprint.hector.api.beans.Row) Date(java.util.Date)

Aggregations

Row (me.prettyprint.hector.api.beans.Row)6 Date (java.util.Date)4 HColumn (me.prettyprint.hector.api.beans.HColumn)3 ChartSeries (com.geminimobile.chart.ChartSeries)1 ChartValueByTime (com.geminimobile.chart.ChartValueByTime)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 ColumnSlice (me.prettyprint.hector.api.beans.ColumnSlice)1 Rows (me.prettyprint.hector.api.beans.Rows)1 SuperRow (me.prettyprint.hector.api.beans.SuperRow)1 QueryResult (me.prettyprint.hector.api.query.QueryResult)1 CassandraRow (org.apache.gora.cassandra.query.CassandraRow)1 CassandraSubColumn (org.apache.gora.cassandra.query.CassandraSubColumn)1