Java Code Examples for org.apache.calcite.sql.SqlNodeList#add()

The following examples show how to use org.apache.calcite.sql.SqlNodeList#add() . 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: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the SELECT statement that putatively feeds rows into an UPDATE
 * statement to be updated.
 *
 * @param call Call to the UPDATE operator
 * @return select statement
 */
protected SqlSelect createSourceSelectForUpdate(SqlUpdate call) {
	final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
	selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
	int ordinal = 0;
	for (SqlNode exp : call.getSourceExpressionList()) {
		// Force unique aliases to avoid a duplicate for Y with
		// SET X=Y
		String alias = SqlUtil.deriveAliasFromOrdinal(ordinal);
		selectList.add(SqlValidatorUtil.addAlias(exp, alias));
		++ordinal;
	}
	SqlNode sourceTable = call.getTargetTable();
	if (call.getAlias() != null) {
		sourceTable =
			SqlValidatorUtil.addAlias(
				sourceTable,
				call.getAlias().getSimple());
	}
	return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable,
		call.getCondition(), null, null, null, null, null, null);
}
 
Example 2
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the SELECT statement that putatively feeds rows into an UPDATE
 * statement to be updated.
 *
 * @param call Call to the UPDATE operator
 * @return select statement
 */
protected SqlSelect createSourceSelectForUpdate(SqlUpdate call) {
	final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
	selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
	int ordinal = 0;
	for (SqlNode exp : call.getSourceExpressionList()) {
		// Force unique aliases to avoid a duplicate for Y with
		// SET X=Y
		String alias = SqlUtil.deriveAliasFromOrdinal(ordinal);
		selectList.add(SqlValidatorUtil.addAlias(exp, alias));
		++ordinal;
	}
	SqlNode sourceTable = call.getTargetTable();
	if (call.getAlias() != null) {
		sourceTable =
			SqlValidatorUtil.addAlias(
				sourceTable,
				call.getAlias().getSimple());
	}
	return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable,
		call.getCondition(), null, null, null, null, null, null);
}
 
Example 3
Source File: SqlCreateHiveDatabase.java    From flink with 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 4
Source File: DremioRelToSqlConverter.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a SqlWindow that adds ORDER BY if op is one of the given functions.
 */
protected static SqlWindow addDummyOrderBy(SqlWindow window, DremioContext
  context, SqlAggFunction op, List<SqlAggFunction> opsToAddClauseFor) {
  if (!SqlNodeList.isEmptyList(window.getOrderList())) {
    return window;
  }

  // Add the ORDER BY if op is one of the given functions.
  for (SqlAggFunction function : opsToAddClauseFor) {
    if (function == op) {
      SqlNodeList dummyOrderByList = new SqlNodeList(POS);
      dummyOrderByList.add(context.field(0));

      return SqlWindow.create(window.getDeclName(), window.getRefName(), window.getPartitionList(),
        dummyOrderByList, SqlLiteral.createBoolean(window.isRows(), POS), window.getLowerBound(),
        window.getUpperBound(), SqlLiteral.createBoolean(window.isAllowPartial(), POS), POS);
    }
  }

  return window;
}
 
Example 5
Source File: SqlCreateHiveView.java    From flink with 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 6
Source File: SqlCreateHiveTable.java    From flink with Apache License 2.0 6 votes vote down vote up
public SqlNodeList toPropList() {
	SqlNodeList list = new SqlNodeList(pos);
	if (serdeClass != null) {
		list.add(HiveDDLUtils.toTableOption(SERDE_LIB_CLASS_NAME, serdeClass, pos));
		if (serdeProps != null) {
			for (SqlNode sqlNode : serdeProps) {
				SqlTableOption option = (SqlTableOption) sqlNode;
				list.add(HiveDDLUtils.toTableOption(SERDE_INFO_PROP_PREFIX + option.getKeyString(),
						option.getValue(), pos));
			}
		}
	} else {
		for (String prop : delimitPropToValue.keySet()) {
			list.add(HiveDDLUtils.toTableOption(prop, delimitPropToValue.get(prop), pos));
		}
	}
	HiveDDLUtils.unescapeProperties(list);
	return list;
}
 
Example 7
Source File: SqlValidatorUtil.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlNode visit(SqlNodeList list) {
  SqlNodeList copy = new SqlNodeList(list.getParserPosition());
  for (SqlNode node : list) {
    copy.add(node.accept(this));
  }
  return copy;
}
 
Example 8
Source File: SqlValidatorUtil.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlNode visit(SqlNodeList list) {
  SqlNodeList copy = new SqlNodeList(list.getParserPosition());
  for (SqlNode node : list) {
    copy.add(node.accept(this));
  }
  return copy;
}
 
Example 9
Source File: SqlAlterHiveTableSerDe.java    From flink with 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 10
Source File: HiveDDLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static SqlNodeList deepCopyColList(SqlNodeList colList) {
	SqlNodeList res = new SqlNodeList(colList.getParserPosition());
	for (SqlNode node : colList) {
		res.add(deepCopyTableColumn((SqlTableColumn) node));
	}
	return res;
}
 
Example 11
Source File: SqlAlterHiveTableLocation.java    From flink with 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 12
Source File: SqlCreateHiveTable.java    From flink with Apache License 2.0 5 votes vote down vote up
public SqlNodeList toPropList() {
	SqlNodeList res = new SqlNodeList(pos);
	if (fileFormat != null) {
		res.add(HiveDDLUtils.toTableOption(STORED_AS_FILE_FORMAT, fileFormat.getSimple(), fileFormat.getParserPosition()));
	} else {
		res.add(HiveDDLUtils.toTableOption(STORED_AS_INPUT_FORMAT, intputFormat, intputFormat.getParserPosition()));
		res.add(HiveDDLUtils.toTableOption(STORED_AS_OUTPUT_FORMAT, outputFormat, outputFormat.getParserPosition()));
	}
	return res;
}
 
Example 13
Source File: SqlCreateHiveTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private static SqlNodeList extractPartColIdentifiers(SqlNodeList partCols) {
	if (partCols == null) {
		return null;
	}
	SqlNodeList res = new SqlNodeList(partCols.getParserPosition());
	for (SqlNode node : partCols) {
		SqlTableColumn partCol = (SqlTableColumn) node;
		res.add(partCol.getName());
	}
	return res;
}
 
Example 14
Source File: SqlAlterHiveTableFileFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
private static SqlNodeList createPropList(SqlIdentifier format) {
	SqlNodeList res = new SqlNodeList(format.getParserPosition());
	res.add(HiveDDLUtils.toTableOption(
			SqlCreateHiveTable.HiveTableStoredAs.STORED_AS_FILE_FORMAT,
			format.getSimple(),
			format.getParserPosition()));
	return res;
}
 
Example 15
Source File: SideParser.java    From alchemy with Apache License 2.0 5 votes vote down vote up
private static SqlNodeList creatFullNewSelectList(String alias, SqlNodeList selectList) {
    SqlNodeList newSelectList = new SqlNodeList( selectList.getParserPosition());
    List<String> names = new ArrayList<>(2);
    names.add(alias);
    names.add("");
    newSelectList.add(new SqlIdentifier(names,new SqlParserPos(0,0)));
    return newSelectList;
}
 
Example 16
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the SELECT statement that putatively feeds rows into a DELETE
 * statement to be deleted.
 *
 * @param call Call to the DELETE operator
 * @return select statement
 */
protected SqlSelect createSourceSelectForDelete(SqlDelete call) {
	final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
	selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
	SqlNode sourceTable = call.getTargetTable();
	if (call.getAlias() != null) {
		sourceTable =
			SqlValidatorUtil.addAlias(
				sourceTable,
				call.getAlias().getSimple());
	}
	return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable,
		call.getCondition(), null, null, null, null, null, null);
}
 
Example 17
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the SELECT statement that putatively feeds rows into a DELETE
 * statement to be deleted.
 *
 * @param call Call to the DELETE operator
 * @return select statement
 */
protected SqlSelect createSourceSelectForDelete(SqlDelete call) {
	final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
	selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
	SqlNode sourceTable = call.getTargetTable();
	if (call.getAlias() != null) {
		sourceTable =
			SqlValidatorUtil.addAlias(
				sourceTable,
				call.getAlias().getSimple());
	}
	return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable,
		call.getCondition(), null, null, null, null, null, null);
}
 
Example 18
Source File: SqlAlterHiveTable.java    From flink with Apache License 2.0 4 votes vote down vote up
public SqlAlterHiveTable(AlterTableOp op, SqlParserPos pos, SqlIdentifier tableName,
		SqlNodeList partSpec, SqlNodeList propertyList) {
	super(pos, tableName, partSpec, propertyList);
	propertyList.add(HiveDDLUtils.toTableOption(ALTER_TABLE_OP, op.name(), pos));
}
 
Example 19
Source File: SqlAlterHiveDatabase.java    From flink with Apache License 2.0 4 votes vote down vote up
public SqlAlterHiveDatabase(SqlParserPos pos, SqlIdentifier databaseName, SqlNodeList propertyList) {
	super(pos, databaseName, propertyList);
	originPropList = new SqlNodeList(propertyList.getList(), propertyList.getParserPosition());
	propertyList.add(HiveDDLUtils.toTableOption(ALTER_DATABASE_OP, getAlterOp().name(), pos));
}