forked from apache/calcite
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
core/src/main/java/org/apache/calcite/sql/dialect/KylinSqlDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* 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.calcite.sql.dialect; | ||
|
||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.sql.SqlAlienSystemTypeNameSpec; | ||
import org.apache.calcite.sql.SqlCall; | ||
import org.apache.calcite.sql.SqlDataTypeSpec; | ||
import org.apache.calcite.sql.SqlDialect; | ||
import org.apache.calcite.sql.SqlNode; | ||
import org.apache.calcite.sql.SqlOperator; | ||
import org.apache.calcite.sql.SqlSyntax; | ||
import org.apache.calcite.sql.SqlWriter; | ||
import org.apache.calcite.sql.fun.SqlStdOperatorTable; | ||
import org.apache.calcite.sql.fun.SqlSubstringFunction; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
import org.apache.calcite.sql.type.BasicSqlType; | ||
import org.apache.calcite.util.RelToSqlConverterUtil; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* A <code>SqlDialect</code> implementation for the Apache Hive database. | ||
*/ | ||
public class KylinSqlDialect extends SqlDialect { | ||
public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT | ||
.withDatabaseProduct(DatabaseProduct.KYLIN) | ||
.withIdentifierQuoteString("\""); | ||
|
||
public static final SqlDialect DEFAULT = new CalciteSqlDialect(DEFAULT_CONTEXT); | ||
|
||
/** | ||
* Creates a HiveSqlDialect. | ||
*/ | ||
public KylinSqlDialect(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override public void unparseOffsetFetch(SqlWriter writer, @Nullable SqlNode offset, | ||
@Nullable SqlNode fetch) { | ||
unparseFetchUsingLimit(writer, offset, fetch); | ||
} | ||
|
||
@Override public void unparseCall(final SqlWriter writer, final SqlCall call, | ||
final int leftPrec, final int rightPrec) { | ||
switch (call.getKind()) { | ||
case POSITION: | ||
final SqlWriter.Frame frame = writer.startFunCall("INSTR"); | ||
writer.sep(","); | ||
call.operand(1).unparse(writer, leftPrec, rightPrec); | ||
writer.sep(","); | ||
call.operand(0).unparse(writer, leftPrec, rightPrec); | ||
if (3 == call.operandCount()) { | ||
throw new RuntimeException("3rd operand Not Supported for Function INSTR in Hive"); | ||
} | ||
writer.endFunCall(frame); | ||
break; | ||
case MOD: | ||
SqlOperator op = SqlStdOperatorTable.PERCENT_REMAINDER; | ||
SqlSyntax.BINARY.unparse(writer, op, call, leftPrec, rightPrec); | ||
break; | ||
case TRIM: | ||
RelToSqlConverterUtil.unparseHiveTrim(writer, call, leftPrec, rightPrec); | ||
break; | ||
case OTHER_FUNCTION: | ||
if (call.getOperator() instanceof SqlSubstringFunction) { | ||
final SqlWriter.Frame funCallFrame = writer.startFunCall(call.getOperator().getName()); | ||
call.operand(0).unparse(writer, leftPrec, rightPrec); | ||
writer.sep(",", true); | ||
call.operand(1).unparse(writer, leftPrec, rightPrec); | ||
if (3 == call.operandCount()) { | ||
writer.sep(",", true); | ||
call.operand(2).unparse(writer, leftPrec, rightPrec); | ||
} | ||
writer.endFunCall(funCallFrame); | ||
} else { | ||
super.unparseCall(writer, call, leftPrec, rightPrec); | ||
} | ||
break; | ||
default: | ||
super.unparseCall(writer, call, leftPrec, rightPrec); | ||
} | ||
} | ||
|
||
@Override public boolean supportsCharSet() { | ||
return false; | ||
} | ||
|
||
@Override public boolean supportsGroupByWithRollup() { | ||
return true; | ||
} | ||
|
||
@Override public boolean supportsGroupByWithCube() { | ||
return true; | ||
} | ||
|
||
@Override public boolean supportsApproxCountDistinct() { | ||
return true; | ||
} | ||
|
||
@Override public boolean supportsNestedAggregations() { | ||
return false; | ||
} | ||
|
||
@Override public @Nullable SqlNode getCastSpec(final RelDataType type) { | ||
if (type instanceof BasicSqlType) { | ||
switch (type.getSqlTypeName()) { | ||
case INTEGER: | ||
SqlAlienSystemTypeNameSpec typeNameSpec = new SqlAlienSystemTypeNameSpec( | ||
"INT", type.getSqlTypeName(), SqlParserPos.ZERO); | ||
return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO); | ||
default: | ||
break; | ||
} | ||
} | ||
return super.getCastSpec(type); | ||
} | ||
} |