Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

>>> [CLI] experimental aitools tools query --output csv SELECT id, id * 2 AS doubled FROM range(3) ORDER BY id
id,doubled
0,0
1,2
2,4

=== statement on the wire

>>> print_requests.py //api/2.0/sql/statements
SELECT id, id * 2 AS doubled FROM range(3) ORDER BY id
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trace $CLI experimental aitools tools query --output csv "SELECT id, id * 2 AS doubled FROM range(3) ORDER BY id"

title "statement on the wire"
trace print_requests.py //api/2.0/sql/statements | jq -r .body.statement
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RecordRequests = true

[[Server]]
Pattern = "POST /api/2.0/sql/statements"
Comment thread
denik marked this conversation as resolved.
Resolved
Response.Body = '''
{
"statement_id": "s1",
"status": {"state": "SUCCEEDED"},
"manifest": {"schema": {"columns": [{"name": "id"}, {"name": "doubled"}]}, "total_chunk_count": 1},
"result": {"data_array": [["0", "0"], ["1", "2"], ["2", "4"]]}
}
'''
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query failed: BAD_REQUEST [TABLE_OR_VIEW_NOT_FOUND], SQLSTATE: 42P01

=== statement on the wire

>>> print_requests.py //api/2.0/sql/statements
SELECT * FROM a_table_that_does_not_exist_zzz
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The real message goes on with advice and the workspace's search path; keep the
# stable parts: error code, error class, the relation and the SQLSTATE.
musterr $CLI experimental aitools tools query --output csv "SELECT * FROM a_table_that_does_not_exist_zzz" 2> LOG.query
contains.py 'query failed: BAD_REQUEST [TABLE_OR_VIEW_NOT_FOUND] The table or view `a_table_that_does_not_exist_zzz` cannot be found' 'SQLSTATE: 42P01' < LOG.query > /dev/null
echo "query failed: BAD_REQUEST [TABLE_OR_VIEW_NOT_FOUND], SQLSTATE: 42P01"

title "statement on the wire"
trace print_requests.py //api/2.0/sql/statements | jq -r .body.statement
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RecordRequests = true

[[Server]]
Pattern = "POST /api/2.0/sql/statements"
Response.Body = '''
{
"statement_id": "s1",
"status": {
"state": "FAILED",
"sql_state": "42P01",
"error": {
"error_code": "BAD_REQUEST",
"message": "[TABLE_OR_VIEW_NOT_FOUND] The table or view `a_table_that_does_not_exist_zzz` cannot be found. Verify the spelling and correctness of the schema and catalog.\nSearch path: [`system`.`session`, `system`.`builtin`].\nSQLSTATE: 42P01; line 1 pos 14"
}
}
}
'''
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

>>> [CLI] experimental aitools tools query --output csv --param maybe= SELECT :maybe IS NULL AS is_null
is_null
true

=== statement on the wire

>>> print_requests.py //api/2.0/sql/statements
{"statement":"SELECT :maybe IS NULL AS is_null","parameters":[{"name":"maybe"}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# An empty value is sent without a value, which the API binds as SQL NULL.
trace $CLI experimental aitools tools query --output csv --param maybe= "SELECT :maybe IS NULL AS is_null"

title "statement on the wire"
trace print_requests.py //api/2.0/sql/statements | jq -c '.body | {statement, parameters}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RecordRequests = true

[[Server]]
Pattern = "POST /api/2.0/sql/statements"
Response.Body = '''
{
"statement_id": "s1",
"status": {"state": "SUCCEEDED"},
"manifest": {"schema": {"columns": [{"name": "is_null"}]}, "total_chunk_count": 1},
"result": {"data_array": [["true"]]}
}
'''
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

>>> [CLI] experimental aitools tools query --output csv --param n:INT=42 --param s=hello SELECT :n AS n, :s AS s
n,s
42,hello

=== statement on the wire

>>> print_requests.py //api/2.0/sql/statements
{"statement":"SELECT :n AS n, :s AS s","parameters":[{"name":"n","type":"INT","value":"42"},{"name":"s","value":"hello"}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trace $CLI experimental aitools tools query --output csv --param n:INT=42 --param s=hello "SELECT :n AS n, :s AS s"

title "statement on the wire"
trace print_requests.py //api/2.0/sql/statements | jq -c '.body | {statement, parameters}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RecordRequests = true

[[Server]]
Pattern = "POST /api/2.0/sql/statements"
Response.Body = '''
{
"statement_id": "s1",
"status": {"state": "SUCCEEDED"},
"manifest": {"schema": {"columns": [{"name": "n"}, {"name": "s"}]}, "total_chunk_count": 1},
"result": {"data_array": [["42", "hello"]]}
}
'''
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

>>> [CLI] experimental aitools tools query --output csv SELECT 1
1
1

=== statement on the wire

>>> print_requests.py //api/2.0/sql/statements
SELECT 1
4 changes: 4 additions & 0 deletions acceptance/experimental/aitools/tools/query/scalar/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trace $CLI experimental aitools tools query --output csv "SELECT 1"

title "statement on the wire"
trace print_requests.py //api/2.0/sql/statements | jq -r .body.statement
12 changes: 12 additions & 0 deletions acceptance/experimental/aitools/tools/query/scalar/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RecordRequests = true

[[Server]]
Pattern = "POST /api/2.0/sql/statements"
Response.Body = '''
{
"statement_id": "s1",
"status": {"state": "SUCCEEDED"},
"manifest": {"schema": {"columns": [{"name": "1"}]}, "total_chunk_count": 1},
"result": {"data_array": [["1"]]}
}
'''
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_uc_warehouse
3 changes: 3 additions & 0 deletions acceptance/experimental/aitools/tools/query/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SQL result types, parameter binding and failures are backend facts: run on every
# cloud. Locally each case stubs the response the real warehouse returns.
Cloud = true
11 changes: 11 additions & 0 deletions acceptance/experimental/aitools/tools/script.prepare
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Called by query/ and statement/. Like the integration tests these replace, the
# SQL tests run on cloud only on Unity Catalog workspaces with a warehouse: the
# shared classic warehouses of the non-UC ones are unreliable to start, and
# CloudEnvs cannot tell azure-prod-ucws from azure-prod.
require_uc_warehouse() {
if [ -n "${CLOUD_ENV:-}" ] && { [ -z "${TEST_METASTORE_ID:-}" ] || [ -z "${TEST_DEFAULT_WAREHOUSE_ID:-}" ]; }; then
echo "SKIP_TEST: needs a Unity Catalog workspace with a warehouse (TEST_METASTORE_ID, TEST_DEFAULT_WAREHOUSE_ID)"
exit 0
fi
export DATABRICKS_WAREHOUSE_ID=$TEST_DEFAULT_WAREHOUSE_ID
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_uc_warehouse
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

>>> [CLI] experimental aitools tools statement submit SELECT count(*) FROM range(100000000000)
{
"statement_id": "[STATEMENT_ID]",
"state": "PENDING",
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
}

>>> [CLI] experimental aitools tools statement cancel [STATEMENT_ID]
{
"statement_id": "[STATEMENT_ID]",
"state": "CANCELED"
}

>>> [CLI] experimental aitools tools statement get [STATEMENT_ID]
{
"statement_id": "[STATEMENT_ID]",
"state": "CANCELED",
"error": {
"message": "statement reached terminal state CANCELED"
}
}

=== cancel request
POST /api/2.0/sql/statements/[STATEMENT_ID]/cancel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Submit returns at once with a PENDING statement, which the cancel then stops.
# Locally the testserver's SQL fake tracks the statement and its cancellation.
trace $CLI experimental aitools tools statement submit "SELECT count(*) FROM range(100000000000)" > out.submit.json
cat out.submit.json
STATEMENT_ID=$(jq -r .statement_id out.submit.json)
add_repl "$STATEMENT_ID" STATEMENT_ID
rm out.submit.json

trace $CLI experimental aitools tools statement cancel "$STATEMENT_ID"

# Cancel is best-effort: a statement that finished before the cancel landed leaves
# nothing to check. Otherwise get polls to the terminal state, CANCELED.
if $CLI experimental aitools tools statement get "$STATEMENT_ID" > LOG.get; then
echo "SKIP_TEST: the statement finished before the cancel landed: $(jq -r .state LOG.get)"
exit 0
fi
musterr trace $CLI experimental aitools tools statement get "$STATEMENT_ID"

title "cancel request"
print_requests.py --summary //cancel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RecordRequests = true
3 changes: 3 additions & 0 deletions acceptance/experimental/aitools/tools/statement/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The statement lifecycle (submit, cancel, terminal state) is a backend fact: run on
# every cloud. Locally the testserver's SQL fake tracks statements and cancellation.
Cloud = true
1 change: 1 addition & 0 deletions acceptance/pipelines/show/failed-statement/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
3 changes: 3 additions & 0 deletions acceptance/pipelines/show/failed-statement/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

>>> [CLI] pipelines show main.default.missing_table
Error: statement failed: BAD_REQUEST: unsupported statement: SELECT * FROM `main`.`default`.`missing_table` LIMIT 11
4 changes: 4 additions & 0 deletions acceptance/pipelines/show/failed-statement/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The testserver fails statements it has no handler for; this pins how the command
# reports a statement that ends FAILED (the real API's response for that case is
# pinned on cloud by experimental/aitools/tools/query/failed-statement).
musterr trace $CLI pipelines show main.default.missing_table
1 change: 1 addition & 0 deletions acceptance/pipelines/show/failed-statement/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Env.DATABRICKS_WAREHOUSE_ID = "wh-test"
1 change: 1 addition & 0 deletions acceptance/telemetry/upload-cloud/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = true
11 changes: 11 additions & 0 deletions acceptance/telemetry/upload-cloud/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== raw response to two test events

>>> [CLI] api post /telemetry-ext --json @body.json
{
"errors": [],
"numProtoSuccess": 2
}

=== the CLI's own upload
All 2 logs uploaded successfully
41 changes: 41 additions & 0 deletions acceptance/telemetry/upload-cloud/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The real /telemetry-ext endpoint accepts the CLI's frontend logs. Locally the
# parent test.toml stubs the endpoint with the same response.
# A host that disables telemetry would upload nothing.
unset DATABRICKS_CLI_DISABLE_TELEMETRY

# A shared workspace can throttle /telemetry-ext past every retry because of other
# CI runs. That says nothing about whether the endpoint accepts these logs: skip.
skip_if_throttled() {
if grep -q 'HTTP/1.1 429' "$1"; then
echo "SKIP_TEST: /telemetry-ext is rate limited on this workspace"
exit 0
fi
}

title "raw response to two test events"
# The response body as the API returns it: every log a success, an empty error list.
event() {
jq -cn --arg id "$(uuid)" --arg name "$1" '{frontend_log_event_id: $id, entry: {databricks_cli_log: {cli_test_event: {name: $name}}}}'
}
jq -n --arg a "$(event VALUE1)" --arg b "$(event VALUE2)" --argjson t "$(date +%s)000" \
'{uploadTime: $t, items: [], protoLogs: [$a, $b]}' > body.json
printf "\n>>> [CLI] api post /telemetry-ext --json @body.json\n"
# Git Bash would rewrite the /telemetry-ext argument as a Windows path.
if ! MSYS_NO_PATHCONV=1 $CLI api post /telemetry-ext --json @body.json --debug > response.json 2> LOG.api; then
skip_if_throttled LOG.api
cat LOG.api >&2
exit 1
fi
jq '{errors, numProtoSuccess}' response.json
rm body.json response.json

title "the CLI's own upload"
# The upload makes one attempt per retry, so a throttled endpoint shows up as a 429
# in the debug log. A generous timeout avoids a timeout retry.
export DATABRICKS_CLI_TELEMETRY_TIMEOUT=30
$CLI selftest send-telemetry --debug 2> LOG.upload
if ! grep -q 'uploaded successfully' LOG.upload; then
skip_if_throttled LOG.upload
fi
contains.py 'All 2 logs uploaded successfully' < LOG.upload > /dev/null
echo "All 2 logs uploaded successfully"
2 changes: 2 additions & 0 deletions acceptance/telemetry/upload-cloud/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Whether the real endpoint accepts the logs is a backend fact: run on every cloud.
Cloud = true
1 change: 1 addition & 0 deletions acceptance/workspace/jobs/tag-limits/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = true
7 changes: 7 additions & 0 deletions acceptance/workspace/jobs/tag-limits/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
key with characters outside the pattern: rejected
key with non-latin1 characters: rejected
empty key: rejected
valid key: accepted, stored tags: {"cafe":"value"}
value café: rejected on aws and gcp, accepted on azure
value with non-latin1 characters: rejected
valid value: accepted, stored tags: {"key":"cafe"}
Loading
Loading