0

I want to modify a SQL query using Calcite. For example

SELECT values FROM data to

SELECT values as v FROM data

I could access SqlNode of select identifier using SqlVisiter implementation.

public Object visit(SqlCall sqlCall) {
    SqlNodeList selectList = ((SqlSelect) sqlCall).getSelectList();
    for (SqlNode sqlNode : selectList) {
        System.out.println(sqlNode.toString());
    }

Now what should I do to update SqlNode?

Shashwat Kumar
  • 5,159
  • 2
  • 30
  • 66

1 Answers1

1

The SqlNode objects in the select list will be instances of SqlIdentifier in this case. So you'll have to cast sqlNode to a SqlIdentifier and then you can call .setName(0, "NEW_NAME"). After this, you call unparse on the original root node to get the new query back.

Michael Mior
  • 28,107
  • 9
  • 89
  • 113