Skip to content

Commit

Permalink
Fix wrong funcname getter again and add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mildbyte committed Oct 14, 2021
1 parent 3bbada7 commit 111aa57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion splitgraph/core/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union

import pglast.node
from psycopg2.sql import SQL, Composed, Identifier
from splitgraph.config import SPLITGRAPH_META_SCHEMA
from splitgraph.core.sql._validation import (
Expand Down Expand Up @@ -44,7 +45,13 @@ def _validate_funccall(node: "Node"):
if len(funcname) != 1:
# e.g. pg_catalog.substring
funcname = funcname[1]
if funcname.val.startswith("pg_"):
if isinstance(funcname, pglast.node.List):
funcname_s = funcname.string_value
elif funcname.node_tag == "String":
funcname_s = funcname.val.value
else:
raise AssertionError
if funcname_s.startswith("pg_"):
raise UnsupportedSQLError("Unsupported function name %s!" % funcname)


Expand Down
4 changes: 4 additions & 0 deletions test/splitgraph/test_sql_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def test_validate_function_call():
succeeds_on_both("SELECT extract_date(42)")


def test_validate_complex_function_call():
succeeds_on_both("SELECT substring(lpad(\"TractId\"::text, 11, '0') from 0 for 6) AS county_id")


def test_validate_pg_function_call():
fails_on_both("SELECT pg_do_shady_things(42)")

Expand Down

0 comments on commit 111aa57

Please sign in to comment.