You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by el...@apache.org on 2017/06/16 02:17:04 UTC

calcite-avatica git commit: [CALCITE-1195] Add a curl+jq example for interacting with Avatica

Repository: calcite-avatica
Updated Branches:
  refs/heads/master 57b57ec1b -> 0020a547c


[CALCITE-1195] Add a curl+jq example for interacting with Avatica

Signed-off-by: Josh Elser <el...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/calcite-avatica/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite-avatica/commit/0020a547
Tree: http://git-wip-us.apache.org/repos/asf/calcite-avatica/tree/0020a547
Diff: http://git-wip-us.apache.org/repos/asf/calcite-avatica/diff/0020a547

Branch: refs/heads/master
Commit: 0020a547c845cc27f7dc048f2b8ac7cb83dc53e0
Parents: 57b57ec
Author: Kevin Risden <ri...@avalonconsult.com>
Authored: Thu Jun 15 19:15:45 2017 -0700
Committer: Josh Elser <el...@apache.org>
Committed: Thu Jun 15 19:15:45 2017 -0700

----------------------------------------------------------------------
 site/_data/docs.yml            |  1 +
 site/_docs/protocol_testing.md | 83 +++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/0020a547/site/_data/docs.yml
----------------------------------------------------------------------
diff --git a/site/_data/docs.yml b/site/_data/docs.yml
index 7c0a0ff..37c8f39 100644
--- a/site/_data/docs.yml
+++ b/site/_data/docs.yml
@@ -30,6 +30,7 @@
   - compatibility
   - custom_client_artifacts
   - docker
+  - protocol_testing
 
 - title: Meta
   docs:

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/0020a547/site/_docs/protocol_testing.md
----------------------------------------------------------------------
diff --git a/site/_docs/protocol_testing.md b/site/_docs/protocol_testing.md
new file mode 100644
index 0000000..2b99c71
--- /dev/null
+++ b/site/_docs/protocol_testing.md
@@ -0,0 +1,83 @@
+---
+layout: docs
+title: Protocol Testing
+sidebar_title: Protocol Testing
+permalink: /docs/protocol_testing.html
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+Building Avatica clients in a variety of languages is one of the primary
+goals 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 with
+the Avatica server.
+
+## Testing with cURL
+
+A trivial way to interact with an Avatica server is using cURL and the JSON
+serialization. The below was tested to work with Avatica 1.10.0:
+
+{% highlight bash %}
+#!/usr/bin/env bash
+
+set -u
+
+AVATICA=$1
+SQL=$2
+
+CONNECTION_ID="conn-$(whoami)-$(date +%s)"
+MAX_ROW_COUNT=100
+NUM_ROWS=2
+OFFSET=0
+
+echo "Open connection"
+openConnectionReq="{\"request\": \"openConnection\",\"connectionId\": \"${CONNECTION_ID}\"}"
+# Example of how to set connection properties with info key
+# openConnectionReqWithProperties="{\"request\": \"openConnection\",\"connectionId\": \"${CONNECTION_ID}\",\"info\": {\"user\": \"SCOTT\",\"password\": \"TIGER\"}}"
+curl -i -w "\n" "$AVATICA" -H "Content-Type: application/json" --data "$openConnectionReq"
+echo
+
+echo "Create statement"
+STATEMENTRSP=$(curl -s "$AVATICA" -H "Content-Type: application/json" --data "{\"request\": \"createStatement\",\"connectionId\": \"${CONNECTION_ID}\"}")
+STATEMENTID=$(echo "$STATEMENTRSP" | jq .statementId)
+echo
+
+echo "PrepareAndExecuteRequest"
+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}}"
+echo
+
+# Loop through all the results
+ISDONE=false
+while ! $ISDONE; do
+  OFFSET=$((OFFSET + NUM_ROWS))
+  echo "FetchRequest - Offset=$OFFSET"
+  FETCHRSP=$(curl -s "$AVATICA" -H "Content-Type: application/json" --data "{\"request\": \"fetch\",\"connectionId\": \"${CONNECTION_ID}\",\"statementId\": $STATEMENTID,\"offset\": ${OFFSET},\"fetchMaxRowCount\": ${NUM_ROWS}}")
+  echo "$FETCHRSP"
+  ISDONE=$(echo "$FETCHRSP" | jq .frame.done)
+  echo
+done
+
+echo "Close statement"
+curl -i -w "\n" "$AVATICA" -H "Content-Type: application/json" --data "{\"request\": \"closeStatement\",\"connectionId\": \"${CONNECTION_ID}\",\"statementId\": $STATEMENTID}"
+echo
+
+echo "Close connection"
+curl -i -w "\n" "$AVATICA" -H "Content-Type: application/json" --data "{\"request\": \"closeConnection\",\"connectionId\": \"${CONNECTION_ID}\"}"
+echo
+{% endhighlight %}