本文整理汇总了Java中org.apache.calcite.sql.SqlDataTypeSpec类的典型用法代码示例。如果您正苦于以下问题:Java SqlDataTypeSpec类的具体用法?Java SqlDataTypeSpec怎么用?Java SqlDataTypeSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlDataTypeSpec类属于org.apache.calcite.sql包,在下文中一共展示了SqlDataTypeSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expandAvg
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
private SqlNode expandAvg(
final SqlNode arg, final RelDataType avgType, final SqlRexContext cx) {
final SqlParserPos pos = SqlParserPos.ZERO;
final SqlNode sum =
SqlStdOperatorTable.SUM.createCall(pos, arg);
final RexNode sumRex = cx.convertExpression(sum);
final SqlNode sumCast;
if (!sumRex.getType().equals(avgType)) {
sumCast = SqlStdOperatorTable.CAST.createCall(pos,
new SqlDataTypeSpec(
new SqlIdentifier(avgType.getSqlTypeName().getName(), pos),
avgType.getPrecision(), avgType.getScale(), null, null, pos));
} else {
sumCast = sum;
}
final SqlNode count =
SqlStdOperatorTable.COUNT.createCall(pos, arg);
return SqlStdOperatorTable.DIVIDE.createCall(
pos, sumCast, count);
}
示例2: getExtendedColumns
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
/**
* Gets a list of extended columns with field indices to the underlying table.
*/
public static List<RelDataTypeField> getExtendedColumns(
RelDataTypeFactory typeFactory, SqlValidatorTable table, SqlNodeList extendedColumns) {
final ImmutableList.Builder<RelDataTypeField> extendedFields =
ImmutableList.builder();
final ExtensibleTable extTable = table.unwrap(ExtensibleTable.class);
int extendedFieldOffset =
extTable == null
? table.getRowType().getFieldCount()
: extTable.getExtendedColumnOffset();
for (final Pair<SqlIdentifier, SqlDataTypeSpec> pair : pairs(extendedColumns)) {
final SqlIdentifier identifier = pair.left;
final SqlDataTypeSpec type = pair.right;
extendedFields.add(
new RelDataTypeFieldImpl(identifier.toString(),
extendedFieldOffset++,
type.deriveType(typeFactory)));
}
return extendedFields.build();
}
示例3: registerTypeAppendOp
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
/**
* Creates and registers a convertlet for an operator in which
* the SQL representation needs the result type appended
* as an extra argument (e.g. CAST).
*
* @param op operator instance
*/
private void registerTypeAppendOp(final SqlOperator op) {
registerOp(
op,
new RexSqlConvertlet() {
public SqlNode convertCall(
RexToSqlNodeConverter converter,
RexCall call) {
SqlNode[] operands =
convertExpressionList(converter, call.operands);
if (operands == null) {
return null;
}
List<SqlNode> operandList =
new ArrayList<SqlNode>(Arrays.asList(operands));
SqlDataTypeSpec typeSpec =
SqlTypeUtil.convertTypeToSpec(call.getType());
operandList.add(typeSpec);
return new SqlBasicCall(
op,
operandList.toArray(new SqlNode[operandList.size()]),
SqlParserPos.ZERO);
}
});
}
示例4: execute
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
public void execute(CalcitePrepare.Context context) {
final List<String> path = context.getDefaultSchemaPath();
CalciteSchema schema = context.getRootSchema();
for (String p : path) {
schema = schema.getSubSchema(p, true);
}
final JavaTypeFactory typeFactory = new JavaTypeFactoryImpl();
final RelDataTypeFactory.Builder builder = typeFactory.builder();
for (Pair<SqlIdentifier, SqlDataTypeSpec> pair : nameTypes()) {
builder.add(pair.left.getSimple(),
pair.right.deriveType(typeFactory, true));
}
final RelDataType rowType = builder.build();
schema.add(name.getSimple(),
new MutableArrayTable(name.getSimple(),
RelDataTypeImpl.proto(rowType)));
}
示例5: visit
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
@Override
public SqlNode visit(SqlDataTypeSpec type) {
for(String strType : disabledType) {
if(type.getTypeName().getSimple().equalsIgnoreCase(strType)) {
unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.DATA_TYPE,
type.getTypeName().getSimple() + " is not supported\n" +
"See Apache Drill JIRA: DRILL-1959");
throw new UnsupportedOperationException();
}
}
return type;
}
示例6: visit
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
@Override
public SqlNode visit(SqlDataTypeSpec type) {
for(String strType : disabledType) {
if(type.getTypeName().getSimple().equalsIgnoreCase(strType)) {
// see DRILL-1959
unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.DATA_TYPE,
type.getTypeName().getSimple() + " is not supported");
throw new UnsupportedOperationException();
}
}
return type;
}
示例7: toSql
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
private SqlNode toSql(RelDataType type) {
switch (dialect.getDatabaseProduct()) {
case MYSQL:
switch (type.getSqlTypeName()) {
case VARCHAR:
// MySQL doesn't have a VARCHAR type, only CHAR.
return new SqlDataTypeSpec(new SqlIdentifier("CHAR", POS),
type.getPrecision(), -1, null, null, POS);
case INTEGER:
return new SqlDataTypeSpec(new SqlIdentifier("_UNSIGNED", POS),
type.getPrecision(), -1, null, null, POS);
default:
}
break;
default:
}
if (type instanceof BasicSqlType) {
return new SqlDataTypeSpec(
new SqlIdentifier(type.getSqlTypeName().name(), POS),
type.getPrecision(),
type.getScale(),
type.getCharset() != null
&& dialect.supportsCharSet()
? type.getCharset().name()
: null,
null,
POS);
}
throw new AssertionError(type); // TODO: implement
}
示例8: field
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
public TableBuilderInfo field(String name, SqlDataTypeSpec type, ColumnConstraint constraint) {
RelDataType dataType = type.deriveType(typeFactory);
if (constraint instanceof ColumnConstraint.PrimaryKey) {
ColumnConstraint.PrimaryKey pk = (ColumnConstraint.PrimaryKey) constraint;
Preconditions.checkState(primaryKey == -1, "There are more than one primary key in the table");
primaryKey = fields.size();
primaryKeyMonotonicity = pk.monotonicity();
}
fields.add(new FieldType(name, dataType));
return this;
}
示例9: toSql
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
private SqlNode toSql(RelDataType type) {
switch (dialect.getDatabaseProduct()) {
case MYSQL:
switch (type.getSqlTypeName()) {
case VARCHAR:
// MySQL doesn't have a VARCHAR type, only CHAR.
return new SqlDataTypeSpec(new SqlIdentifier("CHAR", POS),
type.getPrecision(), -1, null, null, POS);
case INTEGER:
return new SqlDataTypeSpec(new SqlIdentifier("_UNSIGNED", POS),
type.getPrecision(), -1, null, null, POS);
}
break;
}
if (type instanceof BasicSqlType) {
return new SqlDataTypeSpec(
new SqlIdentifier(type.getSqlTypeName().name(), POS),
type.getPrecision(),
type.getScale(),
type.getCharset() != null
&& dialect.supportsCharSet()
? type.getCharset().name()
: null,
null,
POS);
}
return SqlTypeUtil.convertTypeToSpec(type);
//throw new AssertionError(type); // TODO: implement
}
示例10: SqlColumnDeclaration
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
/** Creates a SqlColumnDeclaration; use {@link SqlDdlNodes#column}. */
SqlColumnDeclaration(SqlParserPos pos, SqlIdentifier name,
SqlDataTypeSpec dataType, SqlNode expression,
ColumnStrategy strategy) {
super(pos);
this.name = name;
this.dataType = dataType;
this.expression = expression;
this.strategy = strategy;
}
示例11: visit
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
public RelDataType visit(SqlDataTypeSpec dataType) {
// Q. How can a data type have a type?
// A. When it appears in an expression. (Say as the 2nd arg to the
// CAST operator.)
validateDataType(dataType);
return dataType.deriveType(SqlValidatorImpl.this);
}
示例12: getMonotonicity
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
public SqlMonotonicity getMonotonicity(SqlNode expr) {
return
((expr instanceof SqlLiteral)
|| (expr instanceof SqlDynamicParam)
|| (expr instanceof SqlDataTypeSpec)) ? SqlMonotonicity.CONSTANT
: SqlMonotonicity.NOT_MONOTONIC;
}
示例13: pairs
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
/** Converts a list of extended columns
* (of the form [name0, type0, name1, type1, ...])
* into a list of (name, type) pairs. */
private static List<Pair<SqlIdentifier, SqlDataTypeSpec>> pairs(
SqlNodeList extendedColumns) {
final List list = extendedColumns.getList();
//noinspection unchecked
return Pair.zip(Util.quotientList(list, 2, 0),
Util.quotientList(list, 2, 1));
}
示例14: getCastSpec
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
@Override public SqlNode getCastSpec(RelDataType type) {
switch (type.getSqlTypeName()) {
case VARCHAR:
// MySQL doesn't have a VARCHAR type, only CHAR.
return new SqlDataTypeSpec(new SqlIdentifier("CHAR", SqlParserPos.ZERO),
type.getPrecision(), -1, null, null, SqlParserPos.ZERO);
case INTEGER:
return new SqlDataTypeSpec(new SqlIdentifier("_UNSIGNED", SqlParserPos.ZERO),
type.getPrecision(), -1, null, null, SqlParserPos.ZERO);
}
return super.getCastSpec(type);
}
示例15: unparse
import org.apache.calcite.sql.SqlDataTypeSpec; //导入依赖的package包/类
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("CREATE");
writer.keyword("TABLE");
name.unparse(writer, leftPrec, rightPrec);
SqlWriter.Frame frame = writer.startList("(", ")");
for (Pair<SqlIdentifier, SqlDataTypeSpec> pair : nameTypes()) {
writer.sep(",");
pair.left.unparse(writer, leftPrec, rightPrec); // name
pair.right.unparse(writer, leftPrec, rightPrec); // type
if (Boolean.FALSE.equals(pair.right.getNullable())) {
writer.keyword("NOT NULL");
}
}
writer.endList(frame);
}