Github user sohami commented on a diff in the pull request:

    https://github.com/apache/drill/pull/710#discussion_r95044899
  
    --- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ProfileParser.java ---
    @@ -0,0 +1,217 @@
    +/*
    + * 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.drill.test;
    +
    +import java.io.File;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import javax.json.Json;
    +import javax.json.JsonArray;
    +import javax.json.JsonNumber;
    +import javax.json.JsonObject;
    +import javax.json.JsonReader;
    +import javax.json.JsonValue;
    +
    +/**
    + * Parses a query profile and provides access to various bits of the 
profile
    + * for diagnostic purposes during tests.
    + */
    +
    +public class ProfileParser {
    +
    +  JsonObject profile;
    +  List<String> plans;
    +
    +  public ProfileParser( File file ) throws IOException {
    +    try (FileReader fileReader = new FileReader(file);
    +         JsonReader reader = Json.createReader(fileReader)) {
    +      profile = (JsonObject) reader.read();
    +    }
    +  }
    +
    +  public String getQuery( ) {
    +    return profile.get("query").toString();
    +  }
    +
    +  public String getPlan() {
    +    return profile.get("plan").toString();
    +  }
    +
    +  public List<String> getPlans() {
    +    if ( plans != null ) {
    +      return plans; }
    +    String plan = getPlan( );
    +    Pattern p = Pattern.compile( "(\\d\\d-\\d+[^\\\\]*)\\\\n", 
Pattern.MULTILINE );
    +    Matcher m = p.matcher(plan);
    +    plans = new ArrayList<>( );
    +    while ( m.find() ) {
    +      plans.add(m.group(1));
    +    }
    +    return plans;
    +  }
    +
    +  public String getScan( ) {
    +    int n = getPlans( ).size();
    +    Pattern p = Pattern.compile( "\\d+-\\d+\\s+(\\w+)\\(" );
    --- End diff --
    
    So we are just trying to find if this plan has Scan keyword after fragment 
number. Can't we simply use plan.contains("Scan") ? I guess the scan keyword 
will only be in plans which are actually Scan's.?
    
    Also there can be multiple Scans in the plan right ? In which case we 
should return list of plans here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to