Java Code Examples for org.apache.calcite.sql.SqlCharStringLiteral

The following examples show how to use org.apache.calcite.sql.SqlCharStringLiteral. These examples are extracted from open source projects. 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 Project: Bats   Source File: TypeInferenceUtils.java    License: Apache License 2.0 6 votes vote down vote up
@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 2
Source Project: Bats   Source File: CreateFunctionHandler.java    License: Apache License 2.0 6 votes vote down vote up
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 3
Source Project: flink   Source File: SqlCreateTable.java    License: Apache License 2.0 6 votes vote down vote up
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 4
Source Project: flink   Source File: SqlCreateHiveView.java    License: Apache License 2.0 6 votes vote down vote up
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 5
Source Project: flink   Source File: SqlAddHivePartitions.java    License: Apache License 2.0 6 votes vote down vote up
@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 6
Source Project: flink   Source File: SqlCreateHiveDatabase.java    License: Apache License 2.0 6 votes vote down vote up
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 7
Source Project: flink   Source File: SqlAlterFunction.java    License: Apache License 2.0 6 votes vote down vote up
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 8
Source Project: flink   Source File: SqlCreateView.java    License: Apache License 2.0 6 votes vote down vote up
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 9
Source Project: flink   Source File: SqlCreateTable.java    License: Apache License 2.0 6 votes vote down vote up
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 10
Source Project: calcite   Source File: RelToSqlConverterUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 Project: calcite   Source File: RelToSqlConverterUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 12
Source Project: Bats   Source File: SqlSchema.java    License: Apache License 2.0 5 votes vote down vote up
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 13
Source Project: Bats   Source File: ShowSchemasHandler.java    License: Apache License 2.0 5 votes vote down vote up
/** 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);
}
 
Example 14
Source Project: flink   Source File: SqlTableColumn.java    License: Apache License 2.0 5 votes vote down vote up
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 15
Source Project: flink   Source File: SqlCreateView.java    License: Apache License 2.0 5 votes vote down vote up
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 16
Source Project: flink   Source File: SqlRowType.java    License: Apache License 2.0 5 votes vote down vote up
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 17
Source Project: dremio-oss   Source File: SqlConverter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SqlNode visit(SqlLiteral literal) {
  if (literal instanceof SqlCharStringLiteral) {
    return SqlVarCharStringLiteral.create((SqlCharStringLiteral) literal);
  }
  return literal;
}
 
Example 18
Source Project: flink   Source File: SqlAlterHiveDatabaseLocation.java    License: Apache License 2.0 5 votes vote down vote up
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 19
Source Project: flink   Source File: SqlCreateHiveTable.java    License: Apache License 2.0 5 votes vote down vote up
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 20
Source Project: flink   Source File: SqlCreateHiveTable.java    License: Apache License 2.0 5 votes vote down vote up
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 21
Source Project: flink   Source File: SqlCreateHiveTable.java    License: Apache License 2.0 5 votes vote down vote up
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 22
Source Project: flink   Source File: SqlAlterHiveTableLocation.java    License: Apache License 2.0 5 votes vote down vote up
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 23
Source Project: flink   Source File: HiveDDLUtils.java    License: Apache License 2.0 5 votes vote down vote up
@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 24
Source Project: flink   Source File: SqlAddHivePartitions.java    License: Apache License 2.0 5 votes vote down vote up
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 25
Source Project: flink   Source File: SqlAlterHiveTableSerDe.java    License: Apache License 2.0 5 votes vote down vote up
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 26
Source Project: flink   Source File: ExtendedHiveStructTypeNameSpec.java    License: Apache License 2.0 5 votes vote down vote up
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 27
Source Project: flink   Source File: SqlCreateDatabase.java    License: Apache License 2.0 5 votes vote down vote up
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 28
Source Project: flink   Source File: SqlCreateFunction.java    License: Apache License 2.0 5 votes vote down vote up
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 29
Source Project: flink   Source File: SqlTableColumn.java    License: Apache License 2.0 5 votes vote down vote up
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 30
Source Project: flink   Source File: ExtendedSqlRowTypeNameSpec.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}