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 8cbc383 commit 993e298
Show file tree
Hide file tree
Showing 13 changed files with 619 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SQLMethodInvokeExpr extends SQLExprImpl implements SQLReplaceable,
protected final List<SQLExpr> arguments = new ArrayList<SQLExpr>();
protected String methodName;
protected long methodNameHashCode64;
protected long hashCode64;
protected SQLExpr owner;
protected SQLExpr from;
protected SQLExpr using;
Expand Down Expand Up @@ -87,6 +88,33 @@ public long methodNameHashCode64() {
return methodNameHashCode64;
}

public long hashCode64() {
if (hashCode64 == 0) {
computeHashCode64();
}

return hashCode64;
}

protected void computeHashCode64() {
long hash;
if (owner instanceof SQLName) {
hash = ((SQLName) owner).hashCode64();

hash ^= '.';
hash *= FnvHash.PRIME;
} else if (owner == null) {
hash = FnvHash.BASIC;
} else {
hash = FnvHash.fnv1a_64_lower(owner.toString());

hash ^= '.';
hash *= FnvHash.PRIME;
}
hash = FnvHash.hashCode64(hash, methodName);
hashCode64 = hash;
}

public String getMethodName() {
return this.methodName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,36 @@ public SQLDataType computeDataType() {
}
} else if (resolvedOwnerObject instanceof SQLExprTableSource) {
SQLExpr expr = ((SQLExprTableSource) resolvedOwnerObject).getExpr();
if (expr != null) {
if (expr instanceof SQLName) {
String referencedTableName = ((SQLName) expr).getSimpleName();

SQLSelect select = null;
for (SQLObject parent = resolvedOwnerObject.getParent(); parent != null; parent = parent.getParent()) {
if (parent instanceof SQLSelect) {
select = (SQLSelect) parent;
break;
}
}
if (select != null) {
SQLWithSubqueryClause.Entry queryEntry = select.findWithSubQueryEntry(referencedTableName);
if (queryEntry != null) {
SQLSelectQueryBlock firstQueryBlock = queryEntry.getSubQuery().getFirstQueryBlock();
if (firstQueryBlock != null) {
return firstQueryBlock.findSelectItemAndComputeDataType(this.name);
}
// ignore
}

for (SQLObject parent = select.getParent(); parent != null; parent = parent.getParent()) {
if (parent instanceof SQLSelect) {
queryEntry = ((SQLSelect) parent).findWithSubQueryEntry(referencedTableName);
if (queryEntry != null) {
return queryEntry.getSubQuery().findSelectItemAndComputeDataType(this.name);
}
break;
}
}
}
// skip
}
}
Expand Down
Loading

0 comments on commit 993e298

Please sign in to comment.