/** * Creates a JavaRelImplementor * * @param rexBuilder Builder for {@link RexNode}s * @param implementorTable Table of implementations of operators. Must not be null */ public JavaRelImplementor(RexBuilder rexBuilder, OJRexImplementorTable implementorTable) { super(rexBuilder); Util.pre(rexBuilder != null, "rexBuilder != null"); Util.pre(implementorTable != null, "implementorTable != null"); this.implementorTable = implementorTable; nextVariableId = 0; }
/** @pre SqlTypeUtil.sameNamedType(argTypes[0], (argTypes[1])) */ public RelDataType inferReturnType(SqlOperatorBinding opBinding) { final RelDataType argType0 = opBinding.getOperandType(0); final RelDataType argType1 = opBinding.getOperandType(1); if (!(SqlTypeUtil.inCharOrBinaryFamilies(argType0) && SqlTypeUtil.inCharOrBinaryFamilies(argType1))) { Util.pre( SqlTypeUtil.sameNamedType(argType0, argType1), "SqlTypeUtil.sameNamedType(argTypes[0], argTypes[1])"); } SqlCollation pickedCollation = null; if (SqlTypeUtil.inCharFamily(argType0)) { if (!SqlTypeUtil.isCharTypeComparable(opBinding.collectOperandTypes().subList(0, 2))) { throw opBinding.newError( RESOURCE.typeNotComparable( argType0.getFullTypeString(), argType1.getFullTypeString())); } pickedCollation = SqlCollation.getCoercibilityDyadicOperator( argType0.getCollation(), argType1.getCollation()); assert null != pickedCollation; } // Determine whether result is variable-length SqlTypeName typeName = argType0.getSqlTypeName(); if (SqlTypeUtil.isBoundedVariableWidth(argType1)) { typeName = argType1.getSqlTypeName(); } RelDataType ret; ret = opBinding .getTypeFactory() .createSqlType(typeName, argType0.getPrecision() + argType1.getPrecision()); if (null != pickedCollation) { RelDataType pickedType; if (argType0.getCollation().equals(pickedCollation)) { pickedType = argType0; } else if (argType1.getCollation().equals(pickedCollation)) { pickedType = argType1; } else { throw Util.newInternal("should never come here"); } ret = opBinding .getTypeFactory() .createTypeWithCharsetAndCollation( ret, pickedType.getCharset(), pickedType.getCollation()); } return ret; }
/** * Resolves a multi-part identifier such as "SCHEMA.EMP.EMPNO" to a namespace. The returned * namespace may represent a schema, table, column, etc. * * @pre names.size() > 0 * @post return != null */ public static SqlValidatorNamespace lookup(SqlValidatorScope scope, List<String> names) { Util.pre(names.size() > 0, "names.size() > 0"); SqlValidatorNamespace namespace = null; for (int i = 0; i < names.size(); i++) { String name = names.get(i); if (i == 0) { namespace = scope.resolve(name, null, null); } else { namespace = namespace.lookupChild(name); } } Util.permAssert(namespace != null, "post: namespace != null"); return namespace; }
public RelNode convertSqlToRel(String sql) { Util.pre(sql != null, "sql != null"); final SqlNode sqlQuery; try { sqlQuery = parseQuery(sql); } catch (Exception e) { throw Util.newInternal(e); // todo: better handling } final RelDataTypeFactory typeFactory = getTypeFactory(); final Prepare.CatalogReader catalogReader = createCatalogReader(typeFactory); final SqlValidator validator = createValidator(catalogReader, typeFactory); final SqlToRelConverter converter = createSqlToRelConverter(validator, catalogReader, typeFactory); converter.setTrimUnusedFields(true); final SqlNode validatedQuery = validator.validate(sqlQuery); final RelNode rel = converter.convertQuery(validatedQuery, false, true); Util.post(rel != null, "return != null"); return rel; }
/** * Creates a node. * * @param pos Parser position, must not be null. */ SqlNode(SqlParserPos pos) { Util.pre(pos != null, "pos != null"); this.pos = pos; }