All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arcadedb.query.sql.parser.AggregateProjectionSplit Maven / Gradle / Ivy

There is a newer version: 24.11.2
Show newest version
/*
 * Copyright © 2021-present Arcade Data Ltd ([email protected])
 *
 * Licensed 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.
 *
 * SPDX-FileCopyrightText: 2021-present Arcade Data Ltd ([email protected])
 * SPDX-License-Identifier: Apache-2.0
 */
package com.arcadedb.query.sql.parser;

import java.util.*;

/**
 * This class is used by the query planner to split projections in three parts:
 * 
    *
  • pre-aggregate projections
  • *
  • aggregate projections
  • *
  • post-aggregate projections
  • *
*

* An example: * {@literal * select max(a + b) + (max(b + c * 2) + 1 + 2) * 3 as foo, max(d) + max(e), f from " + className * } * will become * {@literal *

* a + b AS _$$$OALIAS$$_1, b + c * 2 AS _$$$OALIAS$$_3, d AS _$$$OALIAS$$_5, e AS _$$$OALIAS$$_7, f *

* max(_$$$OALIAS$$_1) AS _$$$OALIAS$$_0, max(_$$$OALIAS$$_3) AS _$$$OALIAS$$_2, max(_$$$OALIAS$$_5) AS _$$$OALIAS$$_4, max(_$$$OALIAS$$_7) AS _$$$OALIAS$$_6, f *

* _$$$OALIAS$$_0 + (_$$$OALIAS$$_2 + 1 + 2) * 3 AS `foo`, _$$$OALIAS$$_4 + _$$$OALIAS$$_6 AS `max(d) + max(e)`, f * } * * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) */ public class AggregateProjectionSplit { protected static final String GENERATED_ALIAS_PREFIX = "_$$$OALIAS$$$_"; protected int nextAliasId = 0; protected List preAggregate = new ArrayList<>(); protected List aggregate = new ArrayList<>(); public Identifier getNextAlias() { final Identifier result = new Identifier(GENERATED_ALIAS_PREFIX + (nextAliasId++)); result.internalAlias = true; return result; } public List getPreAggregate() { return preAggregate; } public void setPreAggregate(final List preAggregate) { this.preAggregate = preAggregate; } public List getAggregate() { return aggregate; } public void setAggregate(final List aggregate) { this.aggregate = aggregate; } /** * clean the content, but NOT the counter! */ public void reset() { this.preAggregate.clear(); this.aggregate.clear(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy