/*
 * 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.shardingsphere.core.parse.constant;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

/**
 * Derived column alias.
 *
 * @author zhangliang
 */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum DerivedColumn {
    
    AVG_COUNT_ALIAS("AVG_DERIVED_COUNT_"), 
    AVG_SUM_ALIAS("AVG_DERIVED_SUM_"), 
    ORDER_BY_ALIAS("ORDER_BY_DERIVED_"), 
    GROUP_BY_ALIAS("GROUP_BY_DERIVED_"),
    AGGREGATION_DISTINCT_DERIVED("AGGREGATION_DISTINCT_DERIVED_");
    
    private final String pattern;
    
    /**
     * Get alias of derived column.
     *
     * @param derivedColumnCount derived column count
     * @return alias of derived column
     */
    public String getDerivedColumnAlias(final int derivedColumnCount) {
        return String.format(pattern + "%s", derivedColumnCount);
    }
    
    /**
     * Judge is derived column or not.
     * 
     * @param columnName column name to be judged
     * @return is derived column or not
     */
    public static boolean isDerivedColumn(final String columnName) {
        for (DerivedColumn each : DerivedColumn.values()) {
            if (columnName.startsWith(each.pattern)) {
                return true;
            }
        }
        return false;
    }
}

@@ -919,16 +919,99 @@
 uctor;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Collection;%0A%0A
 /**%0A * D
@@ -1731,24 +1731,460 @@
    %0A    /**%0A
+     * Judge is derived column name or not.%0A     *%0A     * @param columnName column name to be judged%0A     * @return is derived column name or not%0A     */%0A    public static boolean isDerivedColumnName(final String columnName) %7B%0A        for (DerivedColumn each : DerivedColumn.values()) %7B%0A            if (columnName.startsWith(each.pattern)) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A    %0A    /**%0A
      * Judge
@@ -2216,17 +2216,16 @@
 .%0A     *
- 
 %0A     * 
@@ -2424,33 +2424,36 @@
 : DerivedColumn.
-v
+getV
 alues()) %7B%0A     
@@ -2547,32 +2547,32 @@
     %7D%0A        %7D%0A
-
         return f
@@ -2583,10 +2583,269 @@
 ;%0A    %7D%0A
+    %0A    private static Collection%3CDerivedColumn%3E getValues() %7B%0A        Collection%3CDerivedColumn%3E result = new ArrayList%3C%3E(Arrays.asList(DerivedColumn.values()));%0A        result.remove(DerivedColumn.AGGREGATION_DISTINCT_DERIVED);%0A        return result;%0A    %7D%0A
 %7D%0A

add isDerivedColumn()