org.apache.calcite.sql.SqlCharStringLiteral Java Examples
The following examples show how to use
org.apache.calcite.sql.SqlCharStringLiteral.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RelToSqlConverterUtil.java From calcite with Apache License 2.0 | 6 votes |
/** * Creates regex pattern based on the TRIM flag. * * @param call SqlCall contains the values that need to be trimmed * @param trimFlag the trimFlag, either BOTH, LEADING or TRAILING * @return the regex pattern of the character to be trimmed */ public static SqlCharStringLiteral createRegexPatternLiteral(SqlNode call, SqlLiteral trimFlag) { final String regexPattern = ((SqlCharStringLiteral) call).toValue(); String escaped = escapeSpecialChar(regexPattern); final StringBuilder builder = new StringBuilder(); switch (trimFlag.getValueAs(SqlTrimFunction.Flag.class)) { case LEADING: builder.append("^(").append(escaped).append(")*"); break; case TRAILING: builder.append("(").append(escaped).append(")*$"); break; default: builder.append("^(") .append(escaped) .append(")*|(") .append(escaped) .append(")*$"); break; } return SqlLiteral.createCharString(builder.toString(), call.getParserPosition()); }
Example #2
Source File: SqlCreateHiveView.java From flink with Apache License 2.0 | 6 votes |
public SqlCreateHiveView(SqlParserPos pos, SqlIdentifier viewName, SqlNodeList fieldList, SqlNode query, boolean ifNotExists, SqlCharStringLiteral comment, SqlNodeList properties) { super( pos, viewName, fieldList, query, false, false, ifNotExists, HiveDDLUtils.unescapeStringLiteral(comment), properties ); HiveDDLUtils.unescapeProperties(properties); originPropList = new SqlNodeList(properties.getList(), properties.getParserPosition()); // mark it as a hive view properties.add(HiveDDLUtils.toTableOption(CatalogConfig.IS_GENERIC, "false", pos)); }
Example #3
Source File: SqlAddHivePartitions.java From flink with Apache License 2.0 | 6 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword("ALTER TABLE"); tableIdentifier.unparse(writer, leftPrec, rightPrec); writer.newlineAndIndent(); writer.keyword("ADD"); if (ifNotExists()) { writer.keyword("IF NOT EXISTS"); } int opLeftPrec = getOperator().getLeftPrec(); int opRightPrec = getOperator().getRightPrec(); for (int i = 0; i < getPartSpecs().size(); i++) { writer.newlineAndIndent(); SqlNodeList partSpec = getPartSpecs().get(i); writer.keyword("PARTITION"); partSpec.unparse(writer, opLeftPrec, opRightPrec); SqlCharStringLiteral location = partLocations.get(i); if (location != null) { writer.keyword("LOCATION"); location.unparse(writer, opLeftPrec, opRightPrec); } } }
Example #4
Source File: SqlCreateHiveDatabase.java From flink with Apache License 2.0 | 6 votes |
public SqlCreateHiveDatabase(SqlParserPos pos, SqlIdentifier databaseName, SqlNodeList propertyList, SqlCharStringLiteral comment, SqlCharStringLiteral location, boolean ifNotExists) throws ParseException { super( pos, databaseName, HiveDDLUtils.checkReservedDBProperties(propertyList), HiveDDLUtils.unescapeStringLiteral(comment), ifNotExists ); HiveDDLUtils.ensureNonGeneric(propertyList); originPropList = new SqlNodeList(propertyList.getList(), propertyList.getParserPosition()); // mark it as a hive database propertyList.add(HiveDDLUtils.toTableOption(CatalogConfig.IS_GENERIC, "false", pos)); if (location != null) { propertyList.add(new SqlTableOption( SqlLiteral.createCharString(DATABASE_LOCATION_URI, location.getParserPosition()), location, location.getParserPosition())); } this.location = location; }
Example #5
Source File: SqlCreateTable.java From flink with Apache License 2.0 | 6 votes |
public SqlCreateTable( SqlParserPos pos, SqlIdentifier tableName, SqlNodeList columnList, SqlNodeList primaryKeyList, List<SqlNodeList> uniqueKeysList, SqlNodeList propertyList, SqlNodeList partitionKeyList, SqlCharStringLiteral comment) { super(OPERATOR, pos, false, false); this.tableName = requireNonNull(tableName, "Table name is missing"); this.columnList = requireNonNull(columnList, "Column list should not be null"); this.primaryKeyList = primaryKeyList; this.uniqueKeysList = uniqueKeysList; this.propertyList = propertyList; this.partitionKeyList = partitionKeyList; this.comment = comment; }
Example #6
Source File: SqlAlterFunction.java From flink with Apache License 2.0 | 6 votes |
public SqlAlterFunction( SqlParserPos pos, SqlIdentifier functionIdentifier, SqlCharStringLiteral functionClassName, String functionLanguage, boolean ifExists, boolean isTemporary, boolean isSystemFunction) { super(pos); this.functionIdentifier = requireNonNull(functionIdentifier, "functionIdentifier should not be null"); this.functionClassName = requireNonNull(functionClassName, "functionClassName should not be null"); this.isSystemFunction = requireNonNull(isSystemFunction); this.isTemporary = isTemporary; this.functionLanguage = functionLanguage; this.ifExists = ifExists; }
Example #7
Source File: SqlCreateView.java From flink with Apache License 2.0 | 6 votes |
public SqlCreateView( SqlParserPos pos, SqlIdentifier viewName, SqlNodeList fieldList, SqlNode query, boolean replace, boolean isTemporary, boolean ifNotExists, SqlCharStringLiteral comment, SqlNodeList properties) { super(OPERATOR, pos, replace, ifNotExists); this.viewName = requireNonNull(viewName, "viewName should not be null"); this.fieldList = requireNonNull(fieldList, "fieldList should not be null"); this.query = requireNonNull(query, "query should not be null"); this.isTemporary = requireNonNull(isTemporary, "isTemporary should not be null"); this.comment = comment; this.properties = properties; }
Example #8
Source File: SqlCreateTable.java From flink with Apache License 2.0 | 6 votes |
public SqlCreateTable( SqlParserPos pos, SqlIdentifier tableName, SqlNodeList columnList, List<SqlTableConstraint> tableConstraints, SqlNodeList propertyList, SqlNodeList partitionKeyList, @Nullable SqlWatermark watermark, @Nullable SqlCharStringLiteral comment, @Nullable SqlTableLike tableLike, boolean isTemporary) { super(OPERATOR, pos, false, false); this.tableName = requireNonNull(tableName, "tableName should not be null"); this.columnList = requireNonNull(columnList, "columnList should not be null"); this.tableConstraints = requireNonNull(tableConstraints, "table constraints should not be null"); this.propertyList = requireNonNull(propertyList, "propertyList should not be null"); this.partitionKeyList = requireNonNull(partitionKeyList, "partitionKeyList should not be null"); this.watermark = watermark; this.comment = comment; this.tableLike = tableLike; this.isTemporary = isTemporary; }
Example #9
Source File: CreateFunctionHandler.java From Bats with Apache License 2.0 | 6 votes |
JarManager(SqlNode sqlNode, RemoteFunctionRegistry remoteRegistry) throws ForemanSetupException { SqlCreateFunction node = unwrap(sqlNode, SqlCreateFunction.class); this.binaryName = ((SqlCharStringLiteral) node.getJar()).toValue(); String sourceName = JarUtil.getSourceName(binaryName); this.stagingBinary = new Path(remoteRegistry.getStagingArea(), binaryName); this.stagingSource = new Path(remoteRegistry.getStagingArea(), sourceName); this.remoteTmpDir = new Path(remoteRegistry.getTmpArea(), UUID.randomUUID().toString()); this.tmpRemoteBinary = new Path(remoteTmpDir, binaryName); this.tmpRemoteSource = new Path(remoteTmpDir, sourceName); this.registryBinary = new Path(remoteRegistry.getRegistryArea(), binaryName); this.registrySource = new Path(remoteRegistry.getRegistryArea(), sourceName); this.localTmpDir = new Path(Files.createTempDir().toURI()); this.fs = remoteRegistry.getFs(); }
Example #10
Source File: RelToSqlConverterUtil.java From calcite with Apache License 2.0 | 6 votes |
/** * For usage of TRIM, LTRIM and RTRIM in Hive, see * <a href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF">Hive UDF usage</a>. */ public static void unparseHiveTrim( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlLiteral valueToTrim = call.operand(1); if (valueToTrim.toValue().matches("\\s+")) { unparseTrimWithSpace(writer, call, leftPrec, rightPrec); } else { // SELECT TRIM(both 'A' from "ABC") -> SELECT REGEXP_REPLACE("ABC", '^(A)*', '') final SqlLiteral trimFlag = call.operand(0); final SqlCharStringLiteral regexNode = createRegexPatternLiteral(call.operand(1), trimFlag); final SqlCharStringLiteral blankLiteral = SqlLiteral.createCharString("", call.getParserPosition()); final SqlNode[] trimOperands = new SqlNode[] { call.operand(2), regexNode, blankLiteral }; final SqlCall regexReplaceCall = REGEXP_REPLACE.createCall(SqlParserPos.ZERO, trimOperands); regexReplaceCall.unparse(writer, leftPrec, rightPrec); } }
Example #11
Source File: TypeInferenceUtils.java From Bats with Apache License 2.0 | 6 votes |
@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) { final RelDataTypeFactory factory = opBinding.getTypeFactory(); final boolean isNullable = opBinding.getOperandType(1).isNullable(); if (!(opBinding instanceof SqlCallBinding) || !(((SqlCallBinding) opBinding).operand(0) instanceof SqlCharStringLiteral)) { return createCalciteTypeWithNullability(factory, SqlTypeName.ANY, isNullable); } final String part = ((SqlCharStringLiteral) ((SqlCallBinding) opBinding).operand(0)) .getNlsString() .getValue() .toUpperCase(); final SqlTypeName sqlTypeName = getSqlTypeNameForTimeUnit(part); return createCalciteTypeWithNullability( factory, sqlTypeName, isNullable); }
Example #12
Source File: SqlTableColumn.java From flink with Apache License 2.0 | 5 votes |
public SqlTableColumn(SqlIdentifier name, SqlDataTypeSpec type, @Nullable SqlTableConstraint constraint, @Nullable SqlCharStringLiteral comment, SqlParserPos pos) { super(pos); this.name = requireNonNull(name, "Column name should not be null"); this.type = requireNonNull(type, "Column type should not be null"); this.constraint = constraint; this.comment = comment; }
Example #13
Source File: SqlCreateFunction.java From flink with Apache License 2.0 | 5 votes |
public SqlCreateFunction( SqlParserPos pos, SqlIdentifier functionIdentifier, SqlCharStringLiteral functionClassName, String functionLanguage, boolean ifNotExists, boolean isTemporary, boolean isSystemFunction) { super(OPERATOR, pos, false, ifNotExists); this.functionIdentifier = requireNonNull(functionIdentifier); this.functionClassName = requireNonNull(functionClassName); this.isSystemFunction = isSystemFunction; this.isTemporary = isTemporary; this.functionLanguage = functionLanguage; }
Example #14
Source File: SqlCreateDatabase.java From flink with Apache License 2.0 | 5 votes |
public SqlCreateDatabase( SqlParserPos pos, SqlIdentifier databaseName, SqlNodeList propertyList, SqlCharStringLiteral comment, boolean ifNotExists) { super(OPERATOR, pos, false, ifNotExists); this.databaseName = requireNonNull(databaseName, "tableName should not be null"); this.propertyList = requireNonNull(propertyList, "propertyList should not be null"); this.comment = comment; }
Example #15
Source File: ExtendedHiveStructTypeNameSpec.java From flink with Apache License 2.0 | 5 votes |
public ExtendedHiveStructTypeNameSpec( SqlParserPos pos, List<SqlIdentifier> fieldNames, List<SqlDataTypeSpec> fieldTypes, List<SqlCharStringLiteral> comments) throws ParseException { super(pos, fieldNames, fieldTypes, comments, false); if (fieldNames.isEmpty()) { throw new ParseException("STRUCT with no fields is not allowed"); } }
Example #16
Source File: ExtendedSqlRowTypeNameSpec.java From flink with Apache License 2.0 | 5 votes |
/** * Creates a ROW type specification. * * @param pos parser position * @param fieldNames field names * @param fieldTypes field data types * @param comments field comments * @param unparseAsStandard whether to unparse as standard SQL style */ public ExtendedSqlRowTypeNameSpec(SqlParserPos pos, List<SqlIdentifier> fieldNames, List<SqlDataTypeSpec> fieldTypes, List<SqlCharStringLiteral> comments, boolean unparseAsStandard) { super(new SqlIdentifier(SqlTypeName.ROW.getName(), pos), pos); this.fieldNames = fieldNames; this.fieldTypes = fieldTypes; this.comments = comments; this.unparseAsStandard = unparseAsStandard; }
Example #17
Source File: SqlAlterHiveTableSerDe.java From flink with Apache License 2.0 | 5 votes |
public SqlAlterHiveTableSerDe(SqlParserPos pos, SqlIdentifier tableName, SqlNodeList partitionSpec, SqlNodeList propertyList, SqlCharStringLiteral serdeLib) throws ParseException { super(CHANGE_SERDE_PROPS, pos, tableName, partitionSpec, HiveDDLUtils.checkReservedTableProperties(propertyList)); HiveDDLUtils.unescapeProperties(propertyList); // remove the last property which is the ALTER_TABLE_OP origSerDeProps = new SqlNodeList(propertyList.getList().subList(0, propertyList.size() - 1), propertyList.getParserPosition()); appendPrefix(getPropertyList()); if (serdeLib != null) { propertyList.add(HiveDDLUtils.toTableOption( HiveTableRowFormat.SERDE_LIB_CLASS_NAME, serdeLib, serdeLib.getParserPosition())); } this.serdeLib = serdeLib; }
Example #18
Source File: SqlAddHivePartitions.java From flink with Apache License 2.0 | 5 votes |
public SqlAddHivePartitions(SqlParserPos pos, SqlIdentifier tableName, boolean ifNotExists, List<SqlNodeList> partSpecs, List<SqlCharStringLiteral> partLocations) { super(pos, tableName, ifNotExists, partSpecs, toProps(partLocations)); for (SqlNodeList spec : partSpecs) { HiveDDLUtils.unescapePartitionSpec(spec); } this.partLocations = partLocations; }
Example #19
Source File: HiveDDLUtils.java From flink with Apache License 2.0 | 5 votes |
@Override public SqlNode visit(SqlLiteral literal) { if (literal instanceof SqlCharStringLiteral) { SqlCharStringLiteral stringLiteral = (SqlCharStringLiteral) literal; String unescaped = StringEscapeUtils.unescapeJava(stringLiteral.getNlsString().getValue()); return SqlLiteral.createCharString(unescaped, stringLiteral.getParserPosition()); } return literal; }
Example #20
Source File: SqlAlterHiveTableLocation.java From flink with Apache License 2.0 | 5 votes |
private static SqlNodeList createPropList(SqlCharStringLiteral location) { SqlNodeList res = new SqlNodeList(location.getParserPosition()); res.add(HiveDDLUtils.toTableOption( SqlCreateHiveTable.TABLE_LOCATION_URI, location, location.getParserPosition())); return res; }
Example #21
Source File: SqlSchema.java From Bats with Apache License 2.0 | 5 votes |
public Create(SqlParserPos pos, SqlCharStringLiteral schema, SqlNode load, SqlIdentifier table, SqlNode path, SqlNodeList properties, SqlLiteral createType) { super(pos, table); this.schema = schema; this.load = load; this.path = path; this.properties = properties; this.createType = createType; }
Example #22
Source File: SqlCreateHiveTable.java From flink with Apache License 2.0 | 5 votes |
public static HiveTableRowFormat withDelimited(SqlParserPos pos, SqlCharStringLiteral fieldsTerminator, SqlCharStringLiteral escape, SqlCharStringLiteral collectionTerminator, SqlCharStringLiteral mapKeyTerminator, SqlCharStringLiteral linesTerminator, SqlCharStringLiteral nullAs) throws ParseException { return new HiveTableRowFormat(pos, fieldsTerminator, escape, collectionTerminator, mapKeyTerminator, linesTerminator, nullAs, null, null); }
Example #23
Source File: SqlCreateHiveTable.java From flink with Apache License 2.0 | 5 votes |
private HiveTableRowFormat(SqlParserPos pos, SqlCharStringLiteral fieldsTerminator, SqlCharStringLiteral escape, SqlCharStringLiteral collectionTerminator, SqlCharStringLiteral mapKeyTerminator, SqlCharStringLiteral linesTerminator, SqlCharStringLiteral nullAs, SqlCharStringLiteral serdeClass, SqlNodeList serdeProps) throws ParseException { this.pos = pos; if (fieldsTerminator != null) { delimitPropToValue.put(FIELD_DELIM, fieldsTerminator); } if (escape != null) { delimitPropToValue.put(ESCAPE_CHAR, escape); } if (collectionTerminator != null) { delimitPropToValue.put(COLLECTION_DELIM, collectionTerminator); } if (mapKeyTerminator != null) { delimitPropToValue.put(MAPKEY_DELIM, mapKeyTerminator); } if (linesTerminator != null) { delimitPropToValue.put(LINE_DELIM, linesTerminator); } if (nullAs != null) { delimitPropToValue.put(SERIALIZATION_NULL_FORMAT, nullAs); } this.serdeClass = serdeClass; this.serdeProps = serdeProps; validate(); }
Example #24
Source File: SqlCreateHiveTable.java From flink with Apache License 2.0 | 5 votes |
private HiveTableStoredAs(SqlParserPos pos, SqlIdentifier fileFormat, SqlCharStringLiteral intputFormat, SqlCharStringLiteral outputFormat) throws ParseException { this.pos = pos; this.fileFormat = fileFormat; this.intputFormat = intputFormat; this.outputFormat = outputFormat; validate(); }
Example #25
Source File: SqlTableColumn.java From flink with Apache License 2.0 | 5 votes |
public SqlTableColumn(SqlIdentifier name, SqlDataTypeSpec type, SqlCharStringLiteral comment, SqlParserPos pos) { super(pos); this.name = requireNonNull(name, "Column name should not be null"); this.type = requireNonNull(type, "Column type should not be null"); this.comment = comment; }
Example #26
Source File: SqlCreateView.java From flink with Apache License 2.0 | 5 votes |
public SqlCreateView( SqlParserPos pos, SqlIdentifier viewName, SqlNodeList fieldList, SqlNode query, boolean replace, SqlCharStringLiteral comment) { super(OPERATOR, pos, replace, false); this.viewName = viewName; this.fieldList = fieldList; this.query = query; this.comment = comment; }
Example #27
Source File: SqlRowType.java From flink with Apache License 2.0 | 5 votes |
public SqlRowType(SqlParserPos pos, List<SqlIdentifier> fieldNames, List<SqlDataTypeSpec> fieldTypes, List<SqlCharStringLiteral> comments) { super(SqlTypeName.ROW.getName(), pos); this.fieldNames = fieldNames; this.fieldTypes = fieldTypes; this.comments = comments; }
Example #28
Source File: SqlConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public SqlNode visit(SqlLiteral literal) { if (literal instanceof SqlCharStringLiteral) { return SqlVarCharStringLiteral.create((SqlCharStringLiteral) literal); } return literal; }
Example #29
Source File: SqlAlterHiveDatabaseLocation.java From flink with Apache License 2.0 | 5 votes |
public SqlAlterHiveDatabaseLocation(SqlParserPos pos, SqlIdentifier databaseName, SqlCharStringLiteral location) { super(pos, databaseName, new SqlNodeList(pos)); getPropertyList().add(new SqlTableOption( SqlLiteral.createCharString(DATABASE_LOCATION_URI, location.getParserPosition()), location, location.getParserPosition())); this.location = location; }
Example #30
Source File: ShowSchemasHandler.java From Bats with Apache License 2.0 | 5 votes |
/** Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.SCHEMATA ... */ @Override public SqlNode rewrite(SqlNode sqlNode) throws ForemanSetupException { SqlShowSchemas node = unwrap(sqlNode, SqlShowSchemas.class); List<SqlNode> selectList = Collections.singletonList(new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO)); SqlNode fromClause = new SqlIdentifier(Arrays.asList(IS_SCHEMA_NAME, InfoSchemaTableType.SCHEMATA.name()), SqlParserPos.ZERO); SqlNode where = null; SqlNode likePattern = node.getLikePattern(); if (likePattern != null) { SqlNode column = new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO); // schema names are case insensitive, wrap column in lower function, pattern to lower case if (likePattern instanceof SqlCharStringLiteral) { NlsString conditionString = ((SqlCharStringLiteral) likePattern).getNlsString(); likePattern = SqlCharStringLiteral.createCharString( conditionString.getValue().toLowerCase(), conditionString.getCharsetName(), likePattern.getParserPosition()); column = SqlStdOperatorTable.LOWER.createCall(SqlParserPos.ZERO, column); } where = DrillParserUtil.createCondition(column, SqlStdOperatorTable.LIKE, likePattern); } else if (node.getWhereClause() != null) { where = node.getWhereClause(); } return new SqlSelect(SqlParserPos.ZERO, null, new SqlNodeList(selectList, SqlParserPos.ZERO), fromClause, where, null, null, null, null, null, null); }