Search in sources :

Example 6 with SelectionSort

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;
        }
    };
}
Also used : Serializable(java.io.Serializable) SelectionSort(com.linkedin.pinot.common.request.SelectionSort) CompositeDocIdValComparator(com.linkedin.pinot.core.query.selection.comparator.CompositeDocIdValComparator) Comparator(java.util.Comparator) Nonnull(javax.annotation.Nonnull)

Example 7 with SelectionSort

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;
}
Also used : ArrayList(java.util.ArrayList) SelectionSort(com.linkedin.pinot.common.request.SelectionSort) HashSet(java.util.HashSet) Nonnull(javax.annotation.Nonnull)

Example 8 with SelectionSort

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;
        }
    };
}
Also used : Serializable(java.io.Serializable) SelectionSort(com.linkedin.pinot.common.request.SelectionSort) CompositeDocIdValComparator(com.linkedin.pinot.core.query.selection.comparator.CompositeDocIdValComparator) Comparator(java.util.Comparator) Nonnull(javax.annotation.Nonnull)

Aggregations

SelectionSort (com.linkedin.pinot.common.request.SelectionSort)8 Nonnull (javax.annotation.Nonnull)4 ArrayList (java.util.ArrayList)3 Selection (com.linkedin.pinot.common.request.Selection)2 CompositeDocIdValComparator (com.linkedin.pinot.core.query.selection.comparator.CompositeDocIdValComparator)2 Serializable (java.io.Serializable)2 Comparator (java.util.Comparator)2 HashSet (java.util.HashSet)2 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)1 AggregationInfo (com.linkedin.pinot.common.request.AggregationInfo)1 BrokerRequest (com.linkedin.pinot.common.request.BrokerRequest)1 FilterQuery (com.linkedin.pinot.common.request.FilterQuery)1 FilterQueryMap (com.linkedin.pinot.common.request.FilterQueryMap)1 GroupBy (com.linkedin.pinot.common.request.GroupBy)1 QuerySource (com.linkedin.pinot.common.request.QuerySource)1 QueryType (com.linkedin.pinot.common.request.QueryType)1 DataSchema (com.linkedin.pinot.common.utils.DataSchema)1 DataSourceMetadata (com.linkedin.pinot.core.common.DataSourceMetadata)1 Pql2CompilationException (com.linkedin.pinot.pql.parsers.Pql2CompilationException)1 TSerializer (org.apache.thrift.TSerializer)1