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

    https://github.com/apache/spark/pull/9202#discussion_r42743817
  
    --- Diff: 
sql/catalyst/src/main/java/org/apache/spark/sql/SqlIdentifierUtil.java ---
    @@ -0,0 +1,322 @@
    +/*
    + * 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.spark.sql;
    +
    +import java.io.IOException;
    +import java.io.StringReader;
    +import java.util.Locale;
    +import java.util.Vector;
    +import org.apache.spark.SparkException;
    +
    +/**
    + * Methods for handling SQL identifiers. These methods were cribbed
    + * from org.apache.derby.iapi.util.IdUtil and
    + * org.apache.derby.iapi.util.StringUtil.
    + */
    +public class SqlIdentifierUtil {
    +
    +  /**
    +   * Quote a string so that it can be used as an identifier or a string
    +   * literal in SQL statements. Identifiers are surrounded by double quotes
    +   * and string literals are surrounded by single quotes. If the string
    +   * contains quote characters, they are escaped.
    +   *
    +   * @param source the string to quote
    +   * @param quote  the character to quote the string with (' or ")
    +   * @return a string quoted with the specified quote character
    +   */
    +  public static String quoteString(String source, char quote) {
    +    // Normally, the quoted string is two characters longer than the source
    +    // string (because of start quote and end quote).
    +    StringBuffer quoted = new StringBuffer(source.length() + 2);
    +    quoted.append(quote);
    +    for (int i = 0; i < source.length(); i++) {
    +      char c = source.charAt(i);
    +      // if the character is a quote, escape it with an extra quote
    +      if (c == quote) quoted.append(quote);
    +      quoted.append(c);
    +    }
    +    quoted.append(quote);
    +    return quoted.toString();
    +  }
    +
    +  /**
    +   * Parse a multi-part (dot separated) SQL identifier from the
    +   * String provided. Raise an excepion
    +   * if the string does not contain valid SQL indentifiers.
    +   * The returned String array contains the normalized form of the
    +   * identifiers.
    +   *
    +   * @param s        The string to be parsed
    +   * @param quoteCharacter The character which frames a delimited id 
(e.g., " or `)
    +   * @param upperCaseIdentifiers True if SQL ids are normalized to upper 
case.
    +   * @return An array of strings made by breaking the input string at its 
dots, '.'.
    +   * @throws SparkException Invalid SQL identifier.
    +   */
    +  public static String[] parseMultiPartSQLIdentifier(
    +      String s,
    +      char quoteCharacter,
    +      boolean upperCaseIdentifiers)
    +      throws SparkException {
    +    StringReader r = new StringReader(s);
    +    String[] qName = parseMultiPartSQLIdentifier(
    +        s,
    +        r,
    +        quoteCharacter,
    +        upperCaseIdentifiers);
    +    verifyEmpty(s, r);
    +    return qName;
    +  }
    +
    +  /**
    +   * Parse a multi-part (dot separated) SQL identifier from the
    +   * String provided. Raise an excepion
    +   * if the string does not contain valid SQL indentifiers.
    +   * The returned String array contains the normalized form of the
    +   * identifiers.
    +   *
    +   * @param orig The full text being parsed
    +   * @param r        The multi-part identifier to be parsed
    +   * @param quoteCharacter The character which frames a delimited id 
(e.g., " or `)
    +   * @param upperCaseIdentifiers True if SQL ids are normalized to upper 
case.
    +   * @return An array of strings made by breaking the input string at its 
dots, '.'.
    +   * @throws SparkException Invalid SQL identifier.
    +   */
    +  private static String[] parseMultiPartSQLIdentifier(
    --- End diff --
    
    A lot of this looks accomplishable more simply with regexes. Is that not 
feasible?


---
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.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to