drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paul-rogers <...@git.apache.org>
Subject [GitHub] drill pull request #710: DRILL-5126: Provide simplified, unified "cluster fi...
Date Sat, 07 Jan 2017 06:27:43 GMT
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/710#discussion_r95053287
  
    --- 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 --
    
    Yes. What we *should* do is provide the JSON version of the query profile in the UI so
that customers/users can send us that form instead of the text form. With the JSON form, parsing
is much simpler.
    
    Yes, this can be simplified. Originally grabbed the other information such as the numbers,
but not now. Also, was being paranoid incase the word "Scan" showed up as a table or field
name, but "Scan(" is probably safe.
    
    And, yes, in the general case there are multiple scans. Changed that also.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message