Skip to content

Commit 7f40150

Browse files
feat: [SNOW-1890085] process data from server
1 parent 0996c46 commit 7f40150

File tree

4 files changed

+146
-64
lines changed

4 files changed

+146
-64
lines changed

src/snowflake/cli/_plugins/dbt/commands.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
import typer
2121
from click import ClickException
2222
from rich.progress import Progress, SpinnerColumn, TextColumn
23-
from snowflake.cli._plugins.dbt.constants import DBT_COMMANDS
23+
from snowflake.cli._plugins.dbt.constants import (
24+
DBT_COMMANDS,
25+
OUTPUT_COLUMN_NAME,
26+
RESULT_COLUMN_NAME,
27+
)
2428
from snowflake.cli._plugins.dbt.manager import DBTManager
2529
from snowflake.cli._plugins.object.command_aliases import add_object_command_aliases
2630
from snowflake.cli._plugins.object.commands import scope_option
@@ -150,12 +154,20 @@ def _dbt_execute(
150154
progress.add_task(description=f"Executing 'dbt {dbt_command}'", total=None)
151155

152156
result = dbt_manager.execute(*execute_args)
153-
columns = [column.name for column in result.description]
154-
success_column_index = columns.index("SUCCESS")
155-
stdout_column_index = columns.index("STDOUT")
156-
is_success, output = [
157-
(row[success_column_index], row[stdout_column_index]) for row in result
158-
][-1]
157+
158+
try:
159+
columns = [column.name for column in result.description]
160+
success_column_index = columns.index(RESULT_COLUMN_NAME)
161+
stdout_column_index = columns.index(OUTPUT_COLUMN_NAME)
162+
except ValueError:
163+
raise ClickException("Malformed server response")
164+
try:
165+
is_success, output = [
166+
(row[success_column_index], row[stdout_column_index])
167+
for row in result
168+
][-1]
169+
except IndexError:
170+
raise ClickException("No data returned from server")
159171

160172
if is_success is True:
161173
return MessageResult(output)

src/snowflake/cli/_plugins/dbt/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
RESULT_COLUMN_NAME = "SUCCESS"
16+
OUTPUT_COLUMN_NAME = "STDOUT"
17+
1518
DBT_COMMANDS = [
1619
"build",
1720
"compile",

0 commit comments

Comments
 (0)