Search in sources :

Example 1 with SelectionSort

use of com.linkedin.pinot.common.request.SelectionSort in project pinot by linkedin.

the class OrderByAstNode method updateBrokerRequest.

@Override
public void updateBrokerRequest(BrokerRequest brokerRequest) {
    Selection selections = brokerRequest.getSelections();
    for (AstNode astNode : getChildren()) {
        if (astNode instanceof OrderByExpressionAstNode) {
            OrderByExpressionAstNode node = (OrderByExpressionAstNode) astNode;
            SelectionSort elem = new SelectionSort();
            elem.setColumn(node.getColumn());
            elem.setIsAsc("asc".equalsIgnoreCase(node.getOrdering()));
            selections.addToSelectionSortSequence(elem);
        } else {
            throw new Pql2CompilationException("Child node of ORDER BY node is not an expression node");
        }
    }
}
Also used : Selection(com.linkedin.pinot.common.request.Selection) SelectionSort(com.linkedin.pinot.common.request.SelectionSort) Pql2CompilationException(com.linkedin.pinot.pql.parsers.Pql2CompilationException)

Example 2 with SelectionSort

use of com.linkedin.pinot.common.request.SelectionSort in project pinot by linkedin.

the class BrokerRequestSerializationTest method testSerialization.

@Test
public static void testSerialization() throws TException {
    BrokerRequest req = new BrokerRequest();
    // Populate Query Type
    QueryType type = new QueryType();
    type.setHasAggregation(true);
    type.setHasFilter(true);
    type.setHasSelection(true);
    type.setHasGroup_by(true);
    req.setQueryType(type);
    // Populate Query source
    QuerySource s = new QuerySource();
    s.setTableName("dummy");
    req.setQuerySource(s);
    req.setDuration("dummy");
    req.setTimeInterval("dummy");
    //Populate Group-By
    GroupBy groupBy = new GroupBy();
    List<String> columns = new ArrayList<String>();
    columns.add("dummy1");
    columns.add("dummy2");
    groupBy.setColumns(columns);
    groupBy.setTopN(100);
    req.setGroupBy(groupBy);
    //Populate Selections
    Selection sel = new Selection();
    sel.setSize(1);
    SelectionSort s2 = new SelectionSort();
    s2.setColumn("dummy1");
    s2.setIsAsc(true);
    sel.addToSelectionSortSequence(s2);
    sel.addToSelectionColumns("dummy1");
    req.setSelections(sel);
    //Populate FilterQuery
    FilterQuery q1 = new FilterQuery();
    q1.setId(1);
    q1.setColumn("dummy1");
    q1.addToValue("dummy1");
    q1.addToNestedFilterQueryIds(2);
    q1.setOperator(FilterOperator.AND);
    FilterQuery q2 = new FilterQuery();
    q2.setId(2);
    q2.setColumn("dummy2");
    q2.addToValue("dummy2");
    q2.setOperator(FilterOperator.AND);
    FilterQueryMap map = new FilterQueryMap();
    map.putToFilterQueryMap(1, q1);
    map.putToFilterQueryMap(2, q2);
    req.setFilterQuery(q1);
    req.setFilterSubQueryMap(map);
    //Populate Aggregations
    AggregationInfo agg = new AggregationInfo();
    agg.setAggregationType("dummy1");
    agg.putToAggregationParams("key1", "dummy1");
    req.addToAggregationsInfo(agg);
    TSerializer normalSerializer = new TSerializer();
    TSerializer compactSerializer = new TSerializer(new TCompactProtocol.Factory());
    normalSerializer.serialize(req);
    compactSerializer.serialize(req);
//    int numRequests = 100000;
//    TimerContext t = MetricsHelper.startTimer();
//    TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
//    //TSerializer serializer = new TSerializer();
//    //Compact : Size 183 , Serialization Latency : 0.03361ms
//    // Normal : Size 385 , Serialization Latency : 0.01144ms
//
//    for (int i = 0; i < numRequests; i++) {
//      try {
//        serializer.serialize(req);
//        //System.out.println(s3.length);
//        //break;
//      } catch (TException e) {
//        e.printStackTrace();
//      }
//    }
//    t.stop();
//    System.out.println("Latency is :" + (t.getLatencyMs() / (float) numRequests));
}
Also used : GroupBy(com.linkedin.pinot.common.request.GroupBy) Selection(com.linkedin.pinot.common.request.Selection) ArrayList(java.util.ArrayList) FilterQuery(com.linkedin.pinot.common.request.FilterQuery) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) TSerializer(org.apache.thrift.TSerializer) FilterQueryMap(com.linkedin.pinot.common.request.FilterQueryMap) QuerySource(com.linkedin.pinot.common.request.QuerySource) SelectionSort(com.linkedin.pinot.common.request.SelectionSort) BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest) AggregationInfo(com.linkedin.pinot.common.request.AggregationInfo) QueryType(com.linkedin.pinot.common.request.QueryType) Test(org.testng.annotations.Test)

Example 3 with SelectionSort

use of com.linkedin.pinot.common.request.SelectionSort in project pinot by linkedin.

the class MSelectionOrderByOperator method initColumnarDataSourcePlanNodeMap.

private void initColumnarDataSourcePlanNodeMap(IndexSegment indexSegment) {
    _selectionColumns.addAll(_selection.getSelectionColumns());
    if ((_selectionColumns.size() == 1) && ((_selectionColumns.toArray(new String[0]))[0].equals("*"))) {
        _selectionColumns.clear();
        _selectionColumns.addAll(Arrays.asList(indexSegment.getColumnNames()));
    }
    if (_selection.getSelectionSortSequence() != null) {
        for (SelectionSort selectionSort : _selection.getSelectionSortSequence()) {
            _selectionColumns.add(selectionSort.getColumn());
        }
    }
}
Also used : SelectionSort(com.linkedin.pinot.common.request.SelectionSort)

Example 4 with SelectionSort

use of com.linkedin.pinot.common.request.SelectionSort in project pinot by linkedin.

the class SelectionOperatorUtils method extractDataSchema.

/**
   * Extract the {@link DataSchema} from sort sequence, selection columns and {@link IndexSegment}. (Inner segment)
   * <p>Inside data schema, we just store each column once (de-duplicated).
   *
   * @param sortSequence sort sequence.
   * @param selectionColumns selection columns.
   * @param indexSegment index segment.
   * @return data schema.
   */
@Nonnull
public static DataSchema extractDataSchema(@Nullable List<SelectionSort> sortSequence, @Nonnull List<String> selectionColumns, @Nonnull IndexSegment indexSegment) {
    List<String> columnList = new ArrayList<>();
    Set<String> columnSet = new HashSet<>();
    if (sortSequence != null) {
        for (SelectionSort selectionSort : sortSequence) {
            String column = selectionSort.getColumn();
            columnList.add(column);
            columnSet.add(column);
        }
    }
    for (String column : selectionColumns) {
        if (!columnSet.contains(column)) {
            columnList.add(column);
            columnSet.add(column);
        }
    }
    int numColumns = columnList.size();
    String[] columns = new String[numColumns];
    DataType[] dataTypes = new DataType[numColumns];
    for (int i = 0; i < numColumns; i++) {
        String column = columnList.get(i);
        columns[i] = column;
        DataSourceMetadata columnMetadata = indexSegment.getDataSource(column).getDataSourceMetadata();
        if (columnMetadata.isSingleValue()) {
            dataTypes[i] = columnMetadata.getDataType();
        } else {
            dataTypes[i] = columnMetadata.getDataType().toMultiValue();
        }
    }
    return new DataSchema(columns, dataTypes);
}
Also used : DataSchema(com.linkedin.pinot.common.utils.DataSchema) DataSourceMetadata(com.linkedin.pinot.core.common.DataSourceMetadata) ArrayList(java.util.ArrayList) SelectionSort(com.linkedin.pinot.common.request.SelectionSort) DataType(com.linkedin.pinot.common.data.FieldSpec.DataType) HashSet(java.util.HashSet) Nonnull(javax.annotation.Nonnull)

Example 5 with SelectionSort

use of com.linkedin.pinot.common.request.SelectionSort in project pinot by linkedin.

the class SelectionOperatorServiceTest method setUp.

@BeforeClass
public void setUp() {
    // SELECT * FROM table ORDER BY int DESC LIMIT 1, 2.
    _selectionOrderBy.setSelectionColumns(Arrays.asList(_columnNames));
    SelectionSort selectionSort = new SelectionSort();
    selectionSort.setColumn("int");
    selectionSort.setIsAsc(false);
    _selectionOrderBy.setSelectionSortSequence(Collections.singletonList(selectionSort));
    _selectionOrderBy.setSize(2);
    _selectionOrderBy.setOffset(1);
}
Also used : SelectionSort(com.linkedin.pinot.common.request.SelectionSort) BeforeClass(org.testng.annotations.BeforeClass)

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