use of org.apache.hadoop.hbase.hbtop.field.FieldValue in project hbase by apache.
the class TestTopScreenModel method testSort.
@Test
public void testSort() {
// The sort key is LOCALITY
topScreenModel.setSortFieldAndFields(Field.LOCALITY, fields);
FieldValue previous = null;
// Test for ascending sort
topScreenModel.refreshMetricsData();
for (Record record : topScreenModel.getRecords()) {
FieldValue current = record.get(Field.LOCALITY);
if (previous != null) {
assertTrue(current.compareTo(previous) < 0);
}
previous = current;
}
// Test for descending sort
topScreenModel.switchSortOrder();
topScreenModel.refreshMetricsData();
previous = null;
for (Record record : topScreenModel.getRecords()) {
FieldValue current = record.get(Field.LOCALITY);
if (previous != null) {
assertTrue(current.compareTo(previous) > 0);
}
previous = current;
}
}
use of org.apache.hadoop.hbase.hbtop.field.FieldValue in project hbase by apache.
the class TestTopScreenModel method testFilters.
@Test
public void testFilters() {
topScreenModel.addFilter("TABLE==table1", false);
topScreenModel.refreshMetricsData();
for (Record record : topScreenModel.getRecords()) {
FieldValue value = record.get(Field.TABLE);
assertThat(value.asString(), is("table1"));
}
topScreenModel.clearFilters();
topScreenModel.addFilter("TABLE==TABLE1", false);
topScreenModel.refreshMetricsData();
assertThat(topScreenModel.getRecords().size(), is(0));
// Test for ignore case
topScreenModel.clearFilters();
topScreenModel.addFilter("TABLE==TABLE1", true);
topScreenModel.refreshMetricsData();
for (Record record : topScreenModel.getRecords()) {
FieldValue value = record.get(Field.TABLE);
assertThat(value.asString(), is("table1"));
}
}
use of org.apache.hadoop.hbase.hbtop.field.FieldValue in project hbase by apache.
the class TopScreenModel method refreshRecords.
private void refreshRecords(ClusterMetrics clusterMetrics) {
List<Record> records = currentMode.getRecords(clusterMetrics, pushDownFilters);
// Filter and sort
records = records.stream().filter(r -> filters.stream().allMatch(f -> f.execute(r))).sorted((recordLeft, recordRight) -> {
FieldValue left = recordLeft.get(currentSortField);
FieldValue right = recordRight.get(currentSortField);
return (ascendingSort ? 1 : -1) * left.compareTo(right);
}).collect(Collectors.toList());
this.records = Collections.unmodifiableList(records);
}
use of org.apache.hadoop.hbase.hbtop.field.FieldValue in project hbase by apache.
the class ClientModeStrategy method aggregateRecordsAndAddDistinct.
/**
* Aggregate the records and count the unique values for the given distinctField
*
* @param records records to be processed
* @param groupBy Field on which group by needs to be done
* @param distinctField Field whose unique values needs to be counted
* @param uniqueCountAssignedTo a target field to which the unique count is assigned to
* @return aggregated records
*/
List<Record> aggregateRecordsAndAddDistinct(List<Record> records, Field groupBy, Field distinctField, Field uniqueCountAssignedTo) {
List<Record> result = new ArrayList<>();
records.stream().collect(Collectors.groupingBy(r -> r.get(groupBy))).values().forEach(val -> {
Set<FieldValue> distinctValues = new HashSet<>();
Map<Field, FieldValue> map = new HashMap<>();
for (Record record : val) {
for (Map.Entry<Field, FieldValue> field : record.entrySet()) {
if (distinctField.equals(field.getKey())) {
// We will not be adding the field in the new record whose distinct count is required
distinctValues.add(record.get(distinctField));
} else {
if (field.getKey().getFieldValueType() == FieldValueType.STRING) {
map.put(field.getKey(), field.getValue());
} else {
if (map.get(field.getKey()) == null) {
map.put(field.getKey(), field.getValue());
} else {
map.put(field.getKey(), map.get(field.getKey()).plus(field.getValue()));
}
}
}
}
}
// Add unique count field
map.put(uniqueCountAssignedTo, uniqueCountAssignedTo.newValue(distinctValues.size()));
result.add(Record.ofEntries(map.entrySet().stream().map(k -> Record.entry(k.getKey(), k.getValue()))));
});
return result;
}
use of org.apache.hadoop.hbase.hbtop.field.FieldValue in project hbase by apache.
the class RecordFilter method execute.
public boolean execute(Record record) {
FieldValue fieldValue = record.get(field);
if (fieldValue == null) {
return false;
}
if (operator == Operator.EQUAL) {
boolean ret;
if (ignoreCase) {
ret = fieldValue.asString().toLowerCase().contains(value.asString().toLowerCase());
} else {
ret = fieldValue.asString().contains(value.asString());
}
return not != ret;
}
int compare = ignoreCase ? fieldValue.compareToIgnoreCase(value) : fieldValue.compareTo(value);
boolean ret;
switch(operator) {
case DOUBLE_EQUALS:
ret = compare == 0;
break;
case GREATER:
ret = compare > 0;
break;
case GREATER_OR_EQUAL:
ret = compare >= 0;
break;
case LESS:
ret = compare < 0;
break;
case LESS_OR_EQUAL:
ret = compare <= 0;
break;
default:
throw new AssertionError();
}
return not != ret;
}
Aggregations