Skip to content

Commit

Permalink
add permission user in data_prep
Browse files Browse the repository at this point in the history
  • Loading branch information
v-chen_data committed Sep 24, 2024
1 parent d85c83b commit 4c55fa6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion llmfoundry/command_utils/data_prep/convert_delta_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,27 @@ def run_query(
elif method == 'dbconnect':
if spark == None:
raise ValueError(f'sparkSession is required for dbconnect')
df = spark.sql(query)

try:
df = spark.sql(query)
except Exception as e:
from pyspark.errors import AnalysisException
if isinstance(e, AnalysisException):
if 'INSUFFICIENT_PERMISSIONS' in e.message: # pyright: ignore
match = re.search(
r"Schema\s+'([^']+)'",
e.message, # pyright: ignore
)
if match:
schema_name = match.group(1)
action = f'using the schema {schema_name}'
else:
action = 'using the schema'
raise InsufficientPermissionsError(action=action,) from e
raise RuntimeError(
f'Error in querying into schema. Restart sparkSession and try again',
) from e

if collect:
return df.collect()
return df
Expand Down

0 comments on commit 4c55fa6

Please sign in to comment.