Skip to content

Commit

Permalink
improved sql parser bigquery support
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Dec 11, 2024
1 parent 993e298 commit 9c55f11
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public SQLParameter(SQLName name, SQLDataType dataType, SQLExpr defaultValue) {
this.setDefaultValue(defaultValue);
}

public SQLDataType computeDataType() {
return dataType;
}

public SQLExpr getDefaultValue() {
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ public SQLDataType computeDataType() {
}
}

for (SQLObject parent = this.parent; parent != null; parent = parent.getParent()) {
if (parent instanceof SQLCreateFunctionStatement) {
SQLCreateFunctionStatement createFunction = (SQLCreateFunctionStatement) parent;
SQLParameter parameter = createFunction.getParameter(this.name);
return parameter != null ? parameter.computeDataType() : null;
}
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ public List<SQLParameter> getParameters() {
return parameters;
}

public SQLParameter getParameter(String name) {
if (name == null) {
return null;
}
for (SQLParameter parameter : parameters) {
if (name.equals(parameter.getName().getSimpleName())) {
return parameter;
}
}
return null;
}

public void setParameters(List<SQLParameter> parameters) {
this.parameters = parameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,12 @@ SchemaObject acceptCreateTable(SQLCreateTableStatement x) {

if (column == null) {
column = new SQLColumnDefinition();
SQLDataType dataType = selectItem.computeDataType();
SQLDataType dataType = null;
try {
dataType = selectItem.computeDataType();
} catch (Throwable ignored) {
// ignore
}
if (dataType != null) {
column.setDataType(dataType.clone());
}
Expand Down

0 comments on commit 9c55f11

Please sign in to comment.