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

The following examples show how to use org.apache.calcite.sql.SqlNodeList#getParserPosition() . 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   File: SqlShuttle.java    License: Apache License 2.0 6 votes vote down vote up
public SqlNode visit(SqlNodeList nodeList) {
  boolean update = false;
  List<SqlNode> exprs = nodeList.getList();
  int exprCount = exprs.size();
  List<SqlNode> newList = new ArrayList<>(exprCount);
  for (SqlNode operand : exprs) {
    SqlNode clonedOperand;
    if (operand == null) {
      clonedOperand = null;
    } else {
      clonedOperand = operand.accept(this);
      if (clonedOperand != operand) {
        update = true;
      }
    }
    newList.add(clonedOperand);
  }
  if (update) {
    return new SqlNodeList(newList, nodeList.getParserPosition());
  } else {
    return nodeList;
  }
}
 
Example 2
Source Project: alchemy   File: SideParser.java    License: Apache License 2.0 6 votes vote down vote up
private static SqlNodeList reduce(SqlNodeList sqlNodes, String alias) {
    if (sqlNodes == null) {
        return sqlNodes;
    }
    SqlNodeList nodes = sqlNodes.clone(new SqlParserPos(0, 0));
    List<SqlNode> newNodes = new ArrayList<>(nodes.size());
    Iterator<SqlNode> sqlNodeIterable = nodes.iterator();
    while (sqlNodeIterable.hasNext()) {
        SqlNode sqlNode = sqlNodeIterable.next();
        sqlNode = reduce(sqlNode, alias);
        if (sqlNode != null) {
            newNodes.add(sqlNode);
        }
    }
    if (newNodes.size() > 0) {
        return new SqlNodeList(newNodes, nodes.getParserPosition());
    } else {
        return null;
    }
}
 
Example 3
Source Project: flink   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 4
Source Project: flink   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 5
Source Project: calcite   File: SqlShuttle.java    License: Apache License 2.0 6 votes vote down vote up
public SqlNode visit(SqlNodeList nodeList) {
  boolean update = false;
  List<SqlNode> exprs = nodeList.getList();
  int exprCount = exprs.size();
  List<SqlNode> newList = new ArrayList<>(exprCount);
  for (SqlNode operand : exprs) {
    SqlNode clonedOperand;
    if (operand == null) {
      clonedOperand = null;
    } else {
      clonedOperand = operand.accept(this);
      if (clonedOperand != operand) {
        update = true;
      }
    }
    newList.add(clonedOperand);
  }
  if (update) {
    return new SqlNodeList(newList, nodeList.getParserPosition());
  } else {
    return nodeList;
  }
}
 
Example 6
Source Project: Bats   File: SqlValidatorUtil.java    License: 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 7
Source Project: alchemy   File: SideParser.java    License: 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 8
Source Project: alchemy   File: SideParser.java    License: Apache License 2.0 5 votes vote down vote up
private static SqlNodeList changeTableName(SqlNodeList sqlNodes, String alias) {
    if (sqlNodes == null) {
        return sqlNodes;
    }
    SqlNodeList nodes = sqlNodes.clone(new SqlParserPos(0, 0));
    List<SqlNode> newNodes = new ArrayList<>(nodes.size());
    Iterator<SqlNode> sqlNodeIterable = nodes.iterator();
    while (sqlNodeIterable.hasNext()) {
        SqlNode sqlNode = sqlNodeIterable.next();
        sqlNode = changeTableName(sqlNode, alias);
        newNodes.add(sqlNode);
    }
    return new SqlNodeList(newNodes, nodes.getParserPosition());
}
 
Example 9
@Override
public SqlNodeList parseSqlStmtList() throws Exception {
  SqlNodeList list = super.parseSqlStmtList();
  return new SqlNodeList(
    list.getList().stream().map(n->n.accept(createConverter())).collect(Collectors.toList()),
    list.getParserPosition()
  );
}
 
Example 10
Source Project: flink   File: SqlCreateHiveTable.java    License: 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 11
Source Project: flink   File: HiveDDLUtils.java    License: 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 12
Source Project: flink   File: SqlAlterHiveTableProps.java    License: Apache License 2.0 5 votes vote down vote up
public SqlAlterHiveTableProps(SqlParserPos pos, SqlIdentifier tableName, SqlNodeList propertyList)
		throws ParseException {
	super(CHANGE_TBL_PROPS, pos, tableName, null, HiveDDLUtils.checkReservedTableProperties(propertyList));
	HiveDDLUtils.unescapeProperties(propertyList);
	// remove the last property which is the ALTER_TABLE_OP
	this.origProps = new SqlNodeList(propertyList.getList().subList(0, propertyList.size() - 1),
			propertyList.getParserPosition());
}
 
Example 13
Source Project: flink   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 14
Source Project: calcite   File: SqlValidatorUtil.java    License: 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 15
Source Project: flink   File: SqlAlterHiveDatabase.java    License: 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));
}