
io.syndesis.dv.lsp.parser.statement.SelectClause Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dv-server Show documentation
Show all versions of dv-server Show documentation
Tool that allows creating, editing and managing dynamic VDBs for the Teiid OpenShift Deployment.
The newest version!
/*
* Copyright (C) 2016 Red Hat, Inc.
*
* 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.
*/
package io.syndesis.dv.lsp.parser.statement;
import java.util.ArrayList;
import java.util.List;
import io.syndesis.dv.lsp.parser.DdlAnalyzerConstants;
import io.syndesis.dv.lsp.parser.DdlAnalyzerException;
import io.syndesis.dv.lsp.parser.DdlTokenAnalyzer;
import org.eclipse.lsp4j.Position;
import org.teiid.query.parser.SQLParserConstants;
import org.teiid.query.parser.Token;
public class SelectClause extends AbstractStatementObject {
private final List selectColumns;
private boolean isAll;
private boolean isDistinct;
private boolean isStar;
private final QueryExpression queryExpression;
public SelectClause(DdlTokenAnalyzer analyzer, QueryExpression queryExpression) {
super(analyzer);
this.selectColumns = new ArrayList();
this.queryExpression = queryExpression;
}
public QueryExpression getQueryExpression() {
return this.queryExpression;
}
public SelectColumn[] getSelectColumns() {
return selectColumns.toArray(new SelectColumn[0]);
}
public void addSelectColumn(SelectColumn selectColumn) {
this.selectColumns.add(selectColumn);
}
@Override
protected void parseAndValidate() {
// Look for SELECT and FROM tokens
Token selectToken = findTokenByKind(SQLParserConstants.SELECT);
if (selectToken != null) {
setFirstTknIndex(getTokenIndex(selectToken));
} else {
this.analyzer.addException(new DdlAnalyzerException("There is no 'SELECT' in your query expression"));
}
// We have the SELECT
// Look for FROM
Token fromToken = findTokenByKind(SQLParserConstants.FROM);
if (fromToken != null) {
setLastTknIndex(getTokenIndex(fromToken) - 1);
} else {
// Assume that the SELECT ends at either the last token before the semicolon
// or the last token if semi-colon isn't there
List tokens = getTokens();
if (tokens.get(tokens.size() - 1).kind == SQLParserConstants.SEMICOLON) {
setLastTknIndex(tokens.size() - 2);
}
}
// Parse SelectColumn's
processSelectTokens();
}
/*
* SELECT ( ALL | DISTINCT )? ( | (
© 2015 - 2025 Weber Informatics LLC | Privacy Policy