use of com.linkedin.pinot.common.request.SelectionSort in project pinot by linkedin.
the class SelectionOperatorService method getTypeCompatibleComparator.
/**
* Helper method to get the type-compatible {@link Comparator} for selection rows. (Inter segment)
* <p>Type-compatible comparator allows compatible types to compare with each other.
*
* @return flexible {@link Comparator} for selection rows.
*/
@Nonnull
private Comparator<Serializable[]> getTypeCompatibleComparator() {
return new Comparator<Serializable[]>() {
@Override
public int compare(Serializable[] o1, Serializable[] o2) {
int numSortColumns = _sortSequence.size();
for (int i = 0; i < numSortColumns; i++) {
int ret = 0;
SelectionSort selectionSort = _sortSequence.get(i);
Serializable v1 = o1[i];
Serializable v2 = o2[i];
// Only compare single-value columns.
if (v1 instanceof Number) {
if (!selectionSort.isIsAsc()) {
ret = Double.compare(((Number) v1).doubleValue(), ((Number) v2).doubleValue());
} else {
ret = Double.compare(((Number) v2).doubleValue(), ((Number) v1).doubleValue());
}
} else if (v1 instanceof String) {
if (!selectionSort.isIsAsc()) {
ret = ((String) v1).compareTo((String) v2);
} else {
ret = ((String) v2).compareTo((String) v1);
}
}
if (ret != 0) {
return ret;
}
}
return 0;
}
};
}
use of com.linkedin.pinot.common.request.SelectionSort in project pinot by linkedin.
the class SelectionOperatorService method getSortSequence.
/**
* Helper method to handle duplicate sort columns.
*
* @return de-duplicated list of sort sequences.
*/
@Nonnull
private List<SelectionSort> getSortSequence(List<SelectionSort> selectionSorts) {
List<SelectionSort> deDupedSelectionSorts = new ArrayList<>();
Set<String> sortColumns = new HashSet<>();
for (SelectionSort selectionSort : selectionSorts) {
String sortColumn = selectionSort.getColumn();
if (!sortColumns.contains(sortColumn)) {
deDupedSelectionSorts.add(selectionSort);
sortColumns.add(sortColumn);
}
}
return deDupedSelectionSorts;
}
use of com.linkedin.pinot.common.request.SelectionSort in project pinot by linkedin.
the class SelectionOperatorService method getStrictComparator.
/**
* Helper method to get the strict {@link Comparator} for selection rows. (Inner segment)
* <p>Strict comparator does not allow any schema mismatch (more performance driven).
*
* @return strict {@link Comparator} for selection rows.
*/
@Nonnull
private Comparator<Serializable[]> getStrictComparator() {
return new Comparator<Serializable[]>() {
@Override
public int compare(Serializable[] o1, Serializable[] o2) {
int numSortColumns = _sortSequence.size();
for (int i = 0; i < numSortColumns; i++) {
int ret = 0;
SelectionSort selectionSort = _sortSequence.get(i);
Serializable v1 = o1[i];
Serializable v2 = o2[i];
// Only compare single-value columns.
switch(_dataSchema.getColumnType(i)) {
case INT:
if (!selectionSort.isIsAsc()) {
ret = ((Integer) v1).compareTo((Integer) v2);
} else {
ret = ((Integer) v2).compareTo((Integer) v1);
}
break;
case LONG:
if (!selectionSort.isIsAsc()) {
ret = ((Long) v1).compareTo((Long) v2);
} else {
ret = ((Long) v2).compareTo((Long) v1);
}
break;
case FLOAT:
if (!selectionSort.isIsAsc()) {
ret = ((Float) v1).compareTo((Float) v2);
} else {
ret = ((Float) v2).compareTo((Float) v1);
}
break;
case DOUBLE:
if (!selectionSort.isIsAsc()) {
ret = ((Double) v1).compareTo((Double) v2);
} else {
ret = ((Double) v2).compareTo((Double) v1);
}
break;
case STRING:
if (!selectionSort.isIsAsc()) {
ret = ((String) v1).compareTo((String) v2);
} else {
ret = ((String) v2).compareTo((String) v1);
}
break;
default:
break;
}
if (ret != 0) {
return ret;
}
}
return 0;
}
};
}
Aggregations