Protocol Testing

Building Avatica clients in a variety of languages is one of the primarygoals of Avatica. There are various tools which can help in this process,but one of the most useful is a reference for how clients interact withthe Avatica server.

Testing with cURL

A trivial way to interact with an Avatica server is using cURL and the JSONserialization. The below was tested to work with Avatica 1.10.0:

  1. #!/usr/bin/env bash
  2. set -u
  3. AVATICA=$1
  4. SQL=$2
  5. CONNECTION_ID="conn-$(whoami)-$(date +%s)"
  6. MAX_ROW_COUNT=100
  7. NUM_ROWS=2
  8. OFFSET=0
  9. echo "Open connection"
  10. openConnectionReq="{\"request\": \"openConnection\",\"connectionId\": \"${CONNECTION_ID}\"}"
  11. # Example of how to set connection properties with info key
  12. # openConnectionReqWithProperties="{\"request\": \"openConnection\",\"connectionId\": \"${CONNECTION_ID}\",\"info\": {\"user\": \"SCOTT\",\"password\": \"TIGER\"}}"
  13. curl -i -w "\n" "$AVATICA" -H "Content-Type: application/json" --data "$openConnectionReq"
  14. echo
  15. echo "Create statement"
  16. STATEMENTRSP=$(curl -s "$AVATICA" -H "Content-Type: application/json" --data "{\"request\": \"createStatement\",\"connectionId\": \"${CONNECTION_ID}\"}")
  17. STATEMENTID=$(echo "$STATEMENTRSP" | jq .statementId)
  18. echo
  19. echo "PrepareAndExecuteRequest"
  20. curl -i -w "\n" "$AVATICA" -H "Content-Type: application/json" --data "{\"request\": \"prepareAndExecute\",\"connectionId\": \"${CONNECTION_ID}\",\"statementId\": $STATEMENTID,\"sql\": \"$SQL\",\"maxRowCount\": ${MAX_ROW_COUNT}, \"maxRowsInFirstFrame\": ${NUM_ROWS}}"
  21. echo
  22. # Loop through all the results
  23. ISDONE=false
  24. while ! $ISDONE; do
  25. OFFSET=$((OFFSET + NUM_ROWS))
  26. echo "FetchRequest - Offset=$OFFSET"
  27. FETCHRSP=$(curl -s "$AVATICA" -H "Content-Type: application/json" --data "{\"request\": \"fetch\",\"connectionId\": \"${CONNECTION_ID}\",\"statementId\": $STATEMENTID,\"offset\": ${OFFSET},\"fetchMaxRowCount\": ${NUM_ROWS}}")
  28. echo "$FETCHRSP"
  29. ISDONE=$(echo "$FETCHRSP" | jq .frame.done)
  30. echo
  31. done
  32. echo "Close statement"
  33. curl -i -w "\n" "$AVATICA" -H "Content-Type: application/json" --data "{\"request\": \"closeStatement\",\"connectionId\": \"${CONNECTION_ID}\",\"statementId\": $STATEMENTID}"
  34. echo
  35. echo "Close connection"
  36. curl -i -w "\n" "$AVATICA" -H "Content-Type: application/json" --data "{\"request\": \"closeConnection\",\"connectionId\": \"${CONNECTION_ID}\"}"
  37. echo