lujiajing1126 commented on a change in pull request #7495:
URL: https://github.com/apache/skywalking/pull/7495#discussion_r692803144



##########
File path: 
oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/dao/BanyanDBTraceQueryDAO.java
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.storage.plugin.banyandb.dao;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+import org.apache.skywalking.banyandb.v1.client.PairQueryCondition;
+import org.apache.skywalking.banyandb.v1.client.TimestampRange;
+import org.apache.skywalking.banyandb.v1.client.TraceQuery;
+import org.apache.skywalking.banyandb.v1.client.TraceQueryResponse;
+import org.apache.skywalking.oap.server.core.analysis.IDManager;
+import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.Tag;
+import 
org.apache.skywalking.oap.server.core.analysis.manual.segment.SegmentRecord;
+import org.apache.skywalking.oap.server.core.query.type.BasicTrace;
+import org.apache.skywalking.oap.server.core.query.type.QueryOrder;
+import org.apache.skywalking.oap.server.core.query.type.Span;
+import org.apache.skywalking.oap.server.core.query.type.TraceBrief;
+import org.apache.skywalking.oap.server.core.query.type.TraceState;
+import org.apache.skywalking.oap.server.core.storage.AbstractDAO;
+import org.apache.skywalking.oap.server.core.storage.query.ITraceQueryDAO;
+import 
org.apache.skywalking.oap.server.storage.plugin.banyandb.BanyanDBStorageClient;
+import org.apache.skywalking.oap.server.storage.plugin.banyandb.BanyanDBSchema;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class BanyanDBTraceQueryDAO extends AbstractDAO<BanyanDBStorageClient> 
implements ITraceQueryDAO {
+    private static final List<String> BASIC_QUERY_PROJ = 
ImmutableList.of("duration", "state", "start_time", "trace_id", "endpoint_id");
+    private static final List<String> TRACE_ID_QUERY_PROJ;
+
+    static {
+        List<String> fields = new ArrayList<>(BanyanDBSchema.FIELD_NAMES);
+        fields.add("data_binary");
+        TRACE_ID_QUERY_PROJ = ImmutableList.copyOf(fields);
+    }
+
+    public BanyanDBTraceQueryDAO(BanyanDBStorageClient client) {
+        super(client);
+    }
+
+    @Override
+    public TraceBrief queryBasicTraces(long startSecondTB, long endSecondTB, 
long minDuration, long maxDuration, String serviceId, String serviceInstanceId, 
String endpointId, String traceId, int limit, int from, TraceState traceState, 
QueryOrder queryOrder, List<Tag> tags) throws IOException {
+        TraceQuery query;
+        if (startSecondTB != 0 && endSecondTB != 0) {
+            query = new TraceQuery(BanyanDBSchema.NAME, new 
TimestampRange(startSecondTB, endSecondTB), BASIC_QUERY_PROJ);
+        } else {
+            query = new TraceQuery(BanyanDBSchema.NAME, BASIC_QUERY_PROJ);
+        }
+        if (minDuration != 0) {
+            // duration >= minDuration
+            
query.appendCondition(PairQueryCondition.LongQueryCondition.ge("duration", 
minDuration));
+        }
+        if (maxDuration != 0) {
+            // duration <= maxDuration
+            
query.appendCondition(PairQueryCondition.LongQueryCondition.le("duration", 
maxDuration));
+        }
+
+        if (!Strings.isNullOrEmpty(serviceId)) {
+            
query.appendCondition(PairQueryCondition.StringQueryCondition.eq("service_id", 
serviceId));
+        }
+
+        if (!Strings.isNullOrEmpty(serviceInstanceId)) {
+            
query.appendCondition(PairQueryCondition.StringQueryCondition.eq("service_instance_id",
 serviceInstanceId));
+        }
+
+        if (!Strings.isNullOrEmpty(endpointId)) {
+            
query.appendCondition(PairQueryCondition.StringQueryCondition.eq("endpoint_id", 
endpointId));
+        }
+
+        switch (traceState) {
+            case ERROR:
+                
query.appendCondition(PairQueryCondition.LongQueryCondition.eq("state", (long) 
BanyanDBSchema.TraceState.ERROR.getState()));
+                break;
+            case SUCCESS:
+                
query.appendCondition(PairQueryCondition.LongQueryCondition.eq("state", (long) 
BanyanDBSchema.TraceState.SUCCESS.getState()));
+                break;
+            default:
+                
query.appendCondition(PairQueryCondition.LongQueryCondition.eq("state", (long) 
BanyanDBSchema.TraceState.ALL.getState()));
+                break;
+        }
+
+        switch (queryOrder) {
+            case BY_START_TIME:
+                query.setOrderBy(new TraceQuery.OrderBy("start_time", 
TraceQuery.OrderBy.Type.DESC));
+                break;
+            case BY_DURATION:
+                query.setOrderBy(new TraceQuery.OrderBy("duration", 
TraceQuery.OrderBy.Type.DESC));
+                break;
+        }
+
+        query.setLimit(limit);
+        query.setOffset(from);
+
+        // build request
+        TraceQueryResponse response = this.getClient().query(query);
+        TraceBrief brief = new TraceBrief();
+        brief.setTotal(response.size());
+        brief.getTraces().addAll(response.getEntities().stream().map(entity -> 
{
+            BasicTrace trace = new BasicTrace();
+            trace.setDuration(((Long) 
entity.getFields().get(3).getValue()).intValue());
+            
trace.setStart(String.valueOf(entity.getFields().get(4).getValue()));
+            trace.setSegmentId(entity.getId());
+            trace.setError(((Long) 
entity.getFields().get(1).getValue()).intValue() == 1);
+            trace.getTraceIds().add((String) 
entity.getFields().get(0).getValue());
+            trace.getEndpointNames().add(IDManager.EndpointID.analysisId(
+                    (String) entity.getFields().get(2).getValue()
+            ).getEndpointName());
+            return trace;

Review comment:
       > And where is the request fields? I am not sure how BanyanDB server 
implements the logic now when they are loss, but we access them through 
indices, they must be declared. If not, BanyanDB should response nothing.
   
   What do you mean by request fields here?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to