libcouchbase 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +2 -2
  3. data/ext/libcouchbase/CMakeLists.txt +51 -25
  4. data/ext/libcouchbase/CONTRIBUTING.md +46 -65
  5. data/ext/libcouchbase/RELEASE_NOTES.markdown +163 -0
  6. data/ext/libcouchbase/cmake/Modules/DownloadLcbDep.cmake +9 -11
  7. data/ext/libcouchbase/cmake/Modules/FindProfiler.cmake +16 -0
  8. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +6 -6
  9. data/ext/libcouchbase/cmake/config-cmake.h.in +2 -0
  10. data/ext/libcouchbase/cmake/configure +16 -0
  11. data/ext/libcouchbase/example/CMakeLists.txt +17 -2
  12. data/ext/libcouchbase/example/analytics/.gitignore +1 -0
  13. data/ext/libcouchbase/example/analytics/analytics.c +158 -0
  14. data/ext/libcouchbase/example/analytics/build-queries.rb +34 -0
  15. data/ext/libcouchbase/example/analytics/cJSON.c +1 -0
  16. data/ext/libcouchbase/example/analytics/cJSON.h +1 -0
  17. data/ext/libcouchbase/example/analytics/queries.h +113 -0
  18. data/ext/libcouchbase/example/analytics/queries/00-show-dataverse.json +5 -0
  19. data/ext/libcouchbase/example/analytics/queries/01-setup-dataset-breweries.json +6 -0
  20. data/ext/libcouchbase/example/analytics/queries/02-setup-dataset-beers.json +6 -0
  21. data/ext/libcouchbase/example/analytics/queries/03-initiate-shadow.json +6 -0
  22. data/ext/libcouchbase/example/analytics/queries/04-list-datasets.json +7 -0
  23. data/ext/libcouchbase/example/analytics/queries/05-count-breweries.json +5 -0
  24. data/ext/libcouchbase/example/analytics/queries/06-first-brewery.json +6 -0
  25. data/ext/libcouchbase/example/analytics/queries/07-key-based-lookup.json +6 -0
  26. data/ext/libcouchbase/example/analytics/queries/08-exact-match-lookup.json +7 -0
  27. data/ext/libcouchbase/example/analytics/queries/09-exact-match-lookup-different-shape.json +6 -0
  28. data/ext/libcouchbase/example/analytics/queries/10-other-query-filters.json +6 -0
  29. data/ext/libcouchbase/example/analytics/queries/11-equijoin.json +9 -0
  30. data/ext/libcouchbase/example/analytics/queries/12-equijoin-select-star.json +10 -0
  31. data/ext/libcouchbase/example/analytics/queries/13-ansi-join.json +8 -0
  32. data/ext/libcouchbase/example/analytics/queries/14-join-select-values.json +8 -0
  33. data/ext/libcouchbase/example/analytics/queries/15-nested-outer-join.json +7 -0
  34. data/ext/libcouchbase/example/analytics/queries/16-theta-join.json +8 -0
  35. data/ext/libcouchbase/example/analytics/queries/17-existential-quantification.json +9 -0
  36. data/ext/libcouchbase/example/analytics/queries/18-universal-quantification.json +7 -0
  37. data/ext/libcouchbase/example/analytics/queries/19-simple-aggregation.json +6 -0
  38. data/ext/libcouchbase/example/analytics/queries/20-simple-aggregation-unwrapped-value.json +6 -0
  39. data/ext/libcouchbase/example/analytics/queries/21-simple-aggregation-explicit.json +6 -0
  40. data/ext/libcouchbase/example/analytics/queries/22-grouping-and-aggregation.json +6 -0
  41. data/ext/libcouchbase/example/analytics/queries/23-grouping-and-aggregation-with-hint.json +7 -0
  42. data/ext/libcouchbase/example/analytics/queries/24-grouping-and-limits.json +7 -0
  43. data/ext/libcouchbase/example/analytics/queries/25-named-parameters.json +7 -0
  44. data/ext/libcouchbase/example/analytics/queries/26-positional-parameters.json +7 -0
  45. data/ext/libcouchbase/example/crypto/common_provider.c +2 -0
  46. data/ext/libcouchbase/example/crypto/common_provider.h +2 -0
  47. data/ext/libcouchbase/example/crypto/openssl_symmetric_decrypt.c +5 -0
  48. data/ext/libcouchbase/example/crypto/openssl_symmetric_encrypt.c +0 -1
  49. data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.c +16 -26
  50. data/ext/libcouchbase/example/db/db.c +10 -6
  51. data/ext/libcouchbase/example/fts/.gitignore +1 -0
  52. data/ext/libcouchbase/example/fts/build-queries.rb +33 -0
  53. data/ext/libcouchbase/example/fts/fts.c +142 -0
  54. data/ext/libcouchbase/example/fts/queries.h +61 -0
  55. data/ext/libcouchbase/example/fts/queries/00-simple-text-query.json +12 -0
  56. data/ext/libcouchbase/example/fts/queries/01-simple-text-query-on-non-default-index.json +9 -0
  57. data/ext/libcouchbase/example/fts/queries/02-simple-text-query-on-stored-field.json +13 -0
  58. data/ext/libcouchbase/example/fts/queries/03-match-query-with-facet.json +19 -0
  59. data/ext/libcouchbase/example/fts/queries/04-docid-query.json +11 -0
  60. data/ext/libcouchbase/example/fts/queries/05-unanalyzed-term-query-with-fuzziness-level-of-0.json +13 -0
  61. data/ext/libcouchbase/example/fts/queries/06-unanalyzed-term-query-with-fuzziness-level-of-2.json +14 -0
  62. data/ext/libcouchbase/example/fts/queries/07-match-phrase-query.json +13 -0
  63. data/ext/libcouchbase/example/fts/queries/08-phrase-query.json +16 -0
  64. data/ext/libcouchbase/example/fts/queries/09-query-string-query.json +9 -0
  65. data/ext/libcouchbase/example/fts/queries/10-conjunction-query.json +21 -0
  66. data/ext/libcouchbase/example/fts/queries/11-wild-card-query.json +13 -0
  67. data/ext/libcouchbase/example/fts/queries/12-numeric-range-query.json +11 -0
  68. data/ext/libcouchbase/example/fts/queries/13-regexp-query.json +13 -0
  69. data/ext/libcouchbase/example/minimal/.gitignore +1 -0
  70. data/ext/libcouchbase/example/minimal/query.c +185 -0
  71. data/ext/libcouchbase/example/subdoc/subdoc-xattrs.c +2 -2
  72. data/ext/libcouchbase/example/tracing/cJSON.c +1 -1
  73. data/ext/libcouchbase/example/tracing/cJSON.h +1 -1
  74. data/ext/libcouchbase/include/libcouchbase/cbft.h +38 -4
  75. data/ext/libcouchbase/include/libcouchbase/cntl-private.h +8 -97
  76. data/ext/libcouchbase/include/libcouchbase/cntl.h +288 -8
  77. data/ext/libcouchbase/include/libcouchbase/couchbase.h +47 -10
  78. data/ext/libcouchbase/include/libcouchbase/crypto.h +214 -48
  79. data/ext/libcouchbase/include/libcouchbase/deprecated.h +12 -0
  80. data/ext/libcouchbase/include/libcouchbase/error.h +33 -2
  81. data/ext/libcouchbase/include/libcouchbase/ixmgmt.h +1 -1
  82. data/ext/libcouchbase/include/libcouchbase/n1ql.h +87 -13
  83. data/ext/libcouchbase/include/libcouchbase/subdoc.h +3 -7
  84. data/ext/libcouchbase/include/libcouchbase/tracing.h +174 -56
  85. data/ext/libcouchbase/include/libcouchbase/vbucket.h +21 -1
  86. data/ext/libcouchbase/include/libcouchbase/views.h +49 -4
  87. data/ext/libcouchbase/packaging/deb/control +2 -3
  88. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  89. data/ext/libcouchbase/plugins/io/libev/CMakeLists.txt +7 -5
  90. data/ext/libcouchbase/plugins/io/libevent/CMakeLists.txt +7 -5
  91. data/ext/libcouchbase/plugins/io/libuv/CMakeLists.txt +14 -12
  92. data/ext/libcouchbase/plugins/io/libuv/libuv_compat.h +3 -0
  93. data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +14 -6
  94. data/ext/libcouchbase/plugins/io/select/CMakeLists.txt +7 -5
  95. data/ext/libcouchbase/src/bootstrap.cc +6 -1
  96. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +2 -7
  97. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +1 -1
  98. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +4 -11
  99. data/ext/libcouchbase/src/bucketconfig/clconfig.h +29 -36
  100. data/ext/libcouchbase/src/bucketconfig/confmon.cc +4 -2
  101. data/ext/libcouchbase/src/cntl.cc +181 -151
  102. data/ext/libcouchbase/src/config_static.h +1 -1
  103. data/ext/libcouchbase/src/connspec.cc +5 -1
  104. data/ext/libcouchbase/src/connspec.h +3 -1
  105. data/ext/libcouchbase/src/crypto.cc +93 -80
  106. data/ext/libcouchbase/src/dns-srv.cc +1 -1
  107. data/ext/libcouchbase/src/handler.cc +0 -1
  108. data/ext/libcouchbase/src/http/http-priv.h +1 -0
  109. data/ext/libcouchbase/src/http/http.cc +1 -2
  110. data/ext/libcouchbase/src/instance.cc +21 -2
  111. data/ext/libcouchbase/src/internal.h +1 -0
  112. data/ext/libcouchbase/src/lcbio/ctx.c +24 -3
  113. data/ext/libcouchbase/src/lcbio/ioutils.cc +1 -1
  114. data/ext/libcouchbase/src/lcbio/rw-inl.h +22 -1
  115. data/ext/libcouchbase/src/lcbio/ssl.h +2 -0
  116. data/ext/libcouchbase/src/mc/compress.cc +18 -11
  117. data/ext/libcouchbase/src/mc/mcreq.c +2 -0
  118. data/ext/libcouchbase/src/mc/mcreq.h +1 -1
  119. data/ext/libcouchbase/src/mcserver/mcserver.cc +163 -6
  120. data/ext/libcouchbase/src/mcserver/negotiate.cc +17 -7
  121. data/ext/libcouchbase/src/n1ql/n1ql.cc +12 -3
  122. data/ext/libcouchbase/src/newconfig.cc +4 -3
  123. data/ext/libcouchbase/src/nodeinfo.cc +1 -7
  124. data/ext/libcouchbase/src/operations/observe.cc +1 -0
  125. data/ext/libcouchbase/src/operations/ping.cc +5 -3
  126. data/ext/libcouchbase/src/retryq.cc +22 -0
  127. data/ext/libcouchbase/src/retryq.h +2 -1
  128. data/ext/libcouchbase/src/rnd.cc +5 -12
  129. data/ext/libcouchbase/src/settings.c +4 -7
  130. data/ext/libcouchbase/src/settings.h +6 -2
  131. data/ext/libcouchbase/src/strcodecs/base64.c +59 -0
  132. data/ext/libcouchbase/src/strcodecs/strcodecs.h +2 -0
  133. data/ext/libcouchbase/src/trace.h +2 -2
  134. data/ext/libcouchbase/src/tracing/span.cc +177 -45
  135. data/ext/libcouchbase/src/tracing/threshold_logging_tracer.cc +70 -28
  136. data/ext/libcouchbase/src/tracing/tracing-internal.h +33 -48
  137. data/ext/libcouchbase/src/vbucket/vbucket.c +146 -30
  138. data/ext/libcouchbase/src/wait.cc +1 -1
  139. data/ext/libcouchbase/tests/CMakeLists.txt +13 -4
  140. data/ext/libcouchbase/tests/iotests/mock-environment.cc +1 -1
  141. data/ext/libcouchbase/tests/iotests/t_misc.cc +2 -2
  142. data/ext/libcouchbase/tests/iotests/t_views.cc +1 -1
  143. data/ext/libcouchbase/tests/iotests/testutil.cc +3 -2
  144. data/ext/libcouchbase/tests/vbucket/confdata/map_node_present_nodesext_missing_nodes.json +94 -0
  145. data/ext/libcouchbase/tests/vbucket/t_config.cc +15 -0
  146. data/ext/libcouchbase/tools/CMakeLists.txt +11 -6
  147. data/ext/libcouchbase/tools/cbc-handlers.h +9 -0
  148. data/ext/libcouchbase/tools/cbc-proxy.cc +1 -1
  149. data/ext/libcouchbase/tools/cbc.cc +33 -5
  150. data/ext/libcouchbase/tools/common/options.cc +1 -1
  151. data/ext/libcouchbase/tools/extract-packets.rb +110 -0
  152. data/lib/libcouchbase/connection.rb +13 -5
  153. data/lib/libcouchbase/ext/tasks.rb +1 -1
  154. data/lib/libcouchbase/version.rb +1 -1
  155. metadata +62 -7
@@ -1,18 +1,16 @@
1
1
  # DownloadLcbDeb(url location)
2
- FIND_PROGRAM(WGET wget)
3
- FIND_PROGRAM(CURL curl)
4
2
  MACRO(DOWNLOAD_LCB_DEP url dest)
5
- IF(WIN32)
6
- EXECUTE_PROCESS(COMMAND powershell -Command
7
- "(New-Object Net.WebClient).DownloadFile('${url}', '${dest}')" RESULT_VARIABLE DLRC)
8
- ELSEIF(CURL)
9
- EXECUTE_PROCESS(COMMAND "${CURL}" "${url}" -o "${dest}" RESULT_VARIABLE DLRC)
3
+ FIND_PROGRAM(WGET wget)
4
+ FIND_PROGRAM(CURL curl)
5
+ IF(CURL)
6
+ EXECUTE_PROCESS(COMMAND "${CURL}" "${url}" -L -o "${dest}" RESULT_VARIABLE DLRC)
10
7
  ELSEIF(WGET)
11
8
  EXECUTE_PROCESS(COMMAND "${WGET}" "${url}" -O "${dest}" RESULT_VARIABLE DLRC)
12
- ELSE()
13
- MESSAGE(WARNING "Using buggy built-in CMake downloader")
14
- FILE(DOWNLOAD ${url} ${dest} INACTIVITY_TIMEOUT 30 SHOW_PROGRESS)
15
- SET(DLRC 0)
9
+ ENDIF()
10
+ IF(NOT DLRC EQUAL 0)
11
+ MESSAGE(WARNING "Using buggy built-in CMake downloader")
12
+ FILE(DOWNLOAD ${url} ${dest} INACTIVITY_TIMEOUT 30 SHOW_PROGRESS STATUS RET)
13
+ LIST(GET RET 0 DLRC)
16
14
  ENDIF()
17
15
  IF(NOT DLRC EQUAL 0)
18
16
  MESSAGE(FATAL_ERROR "Failed to download ${url}")
@@ -0,0 +1,16 @@
1
+ FIND_LIBRARY(LIBPROFILER
2
+ NAMES profiler
3
+ HINTS
4
+ ENV LIBPROFILER_DIR
5
+ PATHS
6
+ ${DEPS_LIB_DIR}
7
+ ~/Library/Frameworks
8
+ /Library/Frameworks
9
+ /opt/local
10
+ /opt)
11
+
12
+ IF(LIBPROFILER)
13
+ MESSAGE(STATUS "Found libprofiler: ${LIBPROFILER}")
14
+ ELSE()
15
+ MESSAGE(FATAL_ERROR "Unable to find gperftools libprofiler, Try disabling LCB_USE_PROFILER option of CMake.")
16
+ ENDIF()
@@ -16,9 +16,9 @@ MACRO(RUNGIT outvar)
16
16
  OUTPUT_STRIP_TRAILING_WHITESPACE)
17
17
  ENDMACRO()
18
18
 
19
- if (GIT_EXECUTABLE)
20
- RUNGIT(LCB_REVDESCRIBE describe --long)
21
- RUNGIT(LCB_VERSION describe)
19
+ if (GIT_EXECUTABLE AND NOT LCB_SKIP_GIT_VERSION)
20
+ RUNGIT(LCB_REVDESCRIBE describe --long --abbrev=10)
21
+ RUNGIT(LCB_VERSION describe --abbrev=10)
22
22
  STRING(REPLACE "-" "_" LCB_VERSION "${LCB_VERSION}")
23
23
  MESSAGE(STATUS "Sanitized VERSION=${LCB_VERSION}")
24
24
  RUNGIT(LCB_VERSION_CHANGESET rev-parse HEAD)
@@ -42,13 +42,13 @@ ENDIF()
42
42
 
43
43
  IF (NOT LCB_VERSION)
44
44
  SET(LCB_NOGITVERSION ON)
45
- SET(LCB_VERSION "2.8.7")
45
+ SET(LCB_VERSION "2.9.5")
46
46
  ENDIF()
47
47
  IF (NOT LCB_VERSION_CHANGESET)
48
48
  SET(LCB_VERSION_CHANGESET "0xdeadbeef")
49
49
  ENDIF()
50
50
  IF (NOT LCB_VERSION_HEX)
51
- SET(LCB_VERSION_HEX 0x020807)
51
+ SET(LCB_VERSION_HEX 0x020905)
52
52
  ENDIF()
53
53
 
54
54
  # Now parse the version string
@@ -63,7 +63,7 @@ IF(APPLE)
63
63
  ELSE()
64
64
  SET(LCB_SONAME_MAJOR "2")
65
65
  ENDIF()
66
- SET(LCB_SONAME_FULL "${LCB_SONAME_MAJOR}.0.55")
66
+ SET(LCB_SONAME_FULL "${LCB_SONAME_MAJOR}.0.61")
67
67
 
68
68
  MESSAGE(STATUS
69
69
  "libcouchbase ${LCB_VERSION_MAJOR},${LCB_VERSION_MINOR},${LCB_VERSION_PATCH}")
@@ -72,7 +72,9 @@
72
72
  #define LCB_CXX_FLAGS "${CMAKE_CXX_FLAGS}"
73
73
  #define LCB_C_COMPILER "${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}"
74
74
  #define LCB_C_FLAGS "${CMAKE_C_FLAGS}"
75
+ #define LCB_BUILD_TIMESTAMP "${LCB_BUILD_TIMESTAMP}"
75
76
 
76
77
  #define LCB_CLIENT_ID "libcouchbase/" LCB_VERSION_STRING " (" LCB_SYSTEM "; " LCB_SYSTEM_PROCESSOR "; " LCB_C_COMPILER ")"
77
78
 
78
79
  #cmakedefine HAVE_PKCS5_PBKDF2_HMAC
80
+ #cmakedefine LCB_DUMP_PACKETS
@@ -24,6 +24,10 @@ my @HELP_DESCRIPTIONS = (
24
24
  "Create a debug build",
25
25
  "%d", \(my $DEBUG = 0) ],
26
26
 
27
+ [ "enable-profiler", "",
28
+ "Build with profiler support (gperftools)",
29
+ "%d", \(my $USE_PROFILER = 0) ],
30
+
27
31
  [ "disable-tracing", "",
28
32
  "Disable builtin tracing",
29
33
  "%d", \(my $NO_TRACING = 0) ],
@@ -118,6 +122,10 @@ my @HELP_DESCRIPTIONS = (
118
122
  [ "build-dir", "s",
119
123
  "Directory to build in",
120
124
  "%s", \(my $BUILD_DIR = "build") ],
125
+ [ "skip-git-version", "",
126
+ "Skip version detection using git",
127
+ "%d", \(my $SKIP_GIT_VERSION = 0) ],
128
+
121
129
  [ "help", "",
122
130
  "This message", "%s", \(my $WANT_HELP = 0) ]
123
131
  );
@@ -223,6 +231,10 @@ if ($DEBUG) {
223
231
  push @CM_OPTIONS, "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
224
232
  }
225
233
 
234
+ if ($USE_PROFILER) {
235
+ push @CM_OPTIONS, "-DLCB_USE_PROFILER=1";
236
+ }
237
+
226
238
  if ($PREFIX) {
227
239
  push @CM_OPTIONS, "-DCMAKE_INSTALL_PREFIX=$PREFIX";
228
240
  }
@@ -237,6 +249,10 @@ if ($NO_TRACING) {
237
249
  push @CM_OPTIONS, "-DLCB_TRACING=0"
238
250
  }
239
251
 
252
+ if ($SKIP_GIT_VERSION) {
253
+ push @CM_OPTIONS, "-DLCB_SKIP_GIT_VERSION=1"
254
+ }
255
+
240
256
  if ($NO_PLUGINS) {
241
257
  push @CM_OPTIONS, "-DLCB_NO_PLUGINS=1";
242
258
  }
@@ -19,15 +19,30 @@ TARGET_LINK_LIBRARIES(db couchbase)
19
19
  TARGET_LINK_LIBRARIES(vb couchbase)
20
20
 
21
21
  ADD_EXAMPLE(mcc mcc "" "")
22
- ADD_EXAMPLE(minimal minimal "" "")
23
- ADD_EXAMPLE(observe observe "" "")
24
22
  ADD_EXAMPLE(views-example views "" "")
25
23
  ADD_EXAMPLE(tick tick "" "")
24
+ ADD_EXAMPLE(users users "" "")
25
+ ADD_EXAMPLE(fts fts "" "")
26
+ ADD_EXAMPLE(analytics analytics "" "")
26
27
 
27
28
  ADD_EXECUTABLE(subdoc-simple subdoc/subdoc-simple.cc)
28
29
  ADD_EXECUTABLE(subdoc-multi subdoc/subdoc-multi.cc)
30
+ ADD_EXECUTABLE(subdoc-xattrs subdoc/subdoc-xattrs.c)
29
31
  TARGET_LINK_LIBRARIES(subdoc-simple couchbase)
30
32
  TARGET_LINK_LIBRARIES(subdoc-multi couchbase)
33
+ TARGET_LINK_LIBRARIES(subdoc-xattrs couchbase)
34
+
35
+ ADD_EXECUTABLE(minimal minimal/minimal.c)
36
+ TARGET_LINK_LIBRARIES(minimal couchbase)
37
+
38
+ ADD_EXECUTABLE(query minimal/query.c)
39
+ TARGET_LINK_LIBRARIES(query couchbase)
40
+
41
+ ADD_EXECUTABLE(observe observe/observe.c)
42
+ TARGET_LINK_LIBRARIES(observe couchbase)
43
+
44
+ ADD_EXECUTABLE(durability observe/durability.c)
45
+ TARGET_LINK_LIBRARIES(durability couchbase)
31
46
 
32
47
  IF(NOT WIN32)
33
48
  ADD_EXAMPLE(instancepool instancepool pthread "")
@@ -0,0 +1,158 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2018 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /**
19
+
20
+ CFLAGS="-I$(realpath ../../include) -I$(realpath ../../build/generated)"
21
+ LDFLAGS="-L$(realpath ../../build/lib) -lcouchbase -Wl,-rpath=$(realpath ../../build/lib)"
22
+ make analytics
23
+
24
+ */
25
+
26
+ #include <unistd.h>
27
+ #include <stdio.h>
28
+ #include <stdlib.h>
29
+ #include <string.h>
30
+
31
+ #include <libcouchbase/couchbase.h>
32
+ #include <libcouchbase/n1ql.h>
33
+
34
+ #include "queries.h"
35
+ #include "cJSON.h"
36
+
37
+ static void fail(const char *msg)
38
+ {
39
+ printf("[\x1b[31mERROR\x1b[0m] %s\n", msg);
40
+ exit(EXIT_FAILURE);
41
+ }
42
+
43
+ static void check(lcb_error_t err, const char *msg)
44
+ {
45
+ if (err != LCB_SUCCESS) {
46
+ char buf[1024] = {0};
47
+ snprintf(buf, sizeof(buf), "%s: %s\n", msg, lcb_strerror_short(err));
48
+ fail(buf);
49
+ }
50
+ }
51
+
52
+ static int err2color(lcb_error_t err)
53
+ {
54
+ switch (err) {
55
+ case LCB_SUCCESS:
56
+ return 49;
57
+ default:
58
+ return 31;
59
+ }
60
+ }
61
+
62
+ static void row_callback(lcb_t instance, int type, const lcb_RESPN1QL *resp)
63
+ {
64
+ int *idx = (int *)resp->cookie;
65
+ if (resp->rc != LCB_SUCCESS) {
66
+ printf("\x1b[31m%s\x1b[0m", lcb_strerror_short(resp->rc));
67
+ if (resp->htresp) {
68
+ printf(", HTTP status: %d", resp->htresp->htstatus);
69
+ }
70
+ printf("\n");
71
+ if (resp->nrow) {
72
+ cJSON *json;
73
+ char *data = calloc(resp->nrow + 1, sizeof(char));
74
+ memcpy(data, resp->row, resp->nrow);
75
+ json = cJSON_Parse(data);
76
+ if (json && json->type == cJSON_Object) {
77
+ cJSON *errors = cJSON_GetObjectItem(json, "errors");
78
+ if (errors && errors->type == cJSON_Array) {
79
+ int ii, nerrors = cJSON_GetArraySize(errors);
80
+ for (ii = 0; ii < nerrors; ii++) {
81
+ cJSON *err = cJSON_GetArrayItem(errors, ii);
82
+ if (err && err->type == cJSON_Object) {
83
+ cJSON *code, *msg;
84
+ code = cJSON_GetObjectItem(err, "code");
85
+ msg = cJSON_GetObjectItem(err, "msg");
86
+ if (code && code->type == cJSON_Number && msg && msg->type == cJSON_String) {
87
+ printf(
88
+ "\x1b[1mcode\x1b[0m: \x1b[31m%d\x1b[0m, \x1b[1mmessage\x1b[0m: \x1b[31m%s\x1b[0m\n",
89
+ code->valueint, msg->valuestring);
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ free(data);
96
+ }
97
+ }
98
+ if (resp->rflags & LCB_RESP_F_FINAL) {
99
+ printf("\x1b[1mMETA:\x1b[0m ");
100
+ } else {
101
+ printf("\x1b[1mR%d:\x1b[0m ", (*idx)++);
102
+ }
103
+ printf("%.*s\n", (int)resp->nrow, (char *)resp->row);
104
+ if (resp->rflags & LCB_RESP_F_FINAL) {
105
+ printf("\n");
106
+ }
107
+ }
108
+
109
+ int main(int argc, char *argv[])
110
+ {
111
+ lcb_error_t err;
112
+ lcb_t instance;
113
+ char *bucket = NULL;
114
+ size_t ii;
115
+
116
+ if (argc < 2) {
117
+ printf("Usage: %s couchbase://host/beer-sample [ password [ username ] ]\n", argv[0]);
118
+ exit(EXIT_FAILURE);
119
+ }
120
+
121
+ {
122
+ struct lcb_create_st create_options = {0};
123
+ create_options.version = 3;
124
+ create_options.v.v3.connstr = argv[1];
125
+ if (argc > 2) {
126
+ create_options.v.v3.passwd = argv[2];
127
+ }
128
+ if (argc > 3) {
129
+ create_options.v.v3.username = argv[3];
130
+ }
131
+ check(lcb_create(&instance, &create_options), "create couchbase handle");
132
+ check(lcb_connect(instance), "schedule connection");
133
+ lcb_wait(instance);
134
+ check(lcb_get_bootstrap_status(instance), "bootstrap from cluster");
135
+ check(lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_BUCKETNAME, &bucket), "get bucket name");
136
+ if (strcmp(bucket, "beer-sample") != 0) {
137
+ fail("expected bucket to be \"beer-sample\"");
138
+ }
139
+ }
140
+
141
+ for (ii = 0; ii < num_queries; ii++) {
142
+ lcb_CMDN1QL cmd = {0};
143
+ int idx = 0;
144
+ /* NOTE: with this flag, the request will be issued to Analytics service */
145
+ cmd.cmdflags = LCB_CMDN1QL_F_ANALYTICSQUERY;
146
+ cmd.callback = row_callback;
147
+ cmd.query = queries[ii].query;
148
+ cmd.nquery = queries[ii].query_len;
149
+ check(lcb_n1ql_query(instance, &idx, &cmd), "schedule analytics query");
150
+ printf("----> \x1b[1m%s\x1b[0m\n", queries[ii].comment);
151
+ printf("----> \x1b[36m%.*s\x1b[0m\n", (int)queries[ii].query_len, queries[ii].query);
152
+ lcb_wait(instance);
153
+ }
154
+
155
+ /* Now that we're all done, close down the connection handle */
156
+ lcb_destroy(instance);
157
+ return 0;
158
+ }
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Copyright 2018 Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'json'
18
+
19
+ paths = Dir[File.join(__dir__, 'queries', '*.json')].sort
20
+ File.open(File.join(__dir__, 'queries.h'), 'w+') do |out|
21
+ out.puts("// This file was generated by queries.rb")
22
+ out.puts("typedef struct analytics_query_str { const char *comment; size_t query_len; const char *query; } analytics_query_str;")
23
+ out.puts("size_t num_queries = #{paths.size};")
24
+ out.puts("analytics_query_str queries[#{paths.size + 1}] = {")
25
+ paths.each do |path|
26
+ lines = File.readlines(path)
27
+ lines.delete_at(0)
28
+ comment, query = lines.partition { |line| line.start_with?('//') }
29
+ comment_str = comment.map { |line| line.sub(%r(^//\s*), '').strip }.join(' ')
30
+ query_str = JSON.generate(JSON.parse(query.join.strip))
31
+ out.puts("{#{comment_str.inspect},\n #{query_str.size},\n #{query_str.inspect}},\n\n")
32
+ end
33
+ out.puts("{NULL, 0, NULL}};")
34
+ end
@@ -0,0 +1 @@
1
+ ../../contrib/cJSON/cJSON.c
@@ -0,0 +1 @@
1
+ ../../contrib/cJSON/cJSON.h
@@ -0,0 +1,113 @@
1
+ // This file was generated by queries.rb
2
+ typedef struct analytics_query_str { const char *comment; size_t query_len; const char *query; } analytics_query_str;
3
+ size_t num_queries = 27;
4
+ analytics_query_str queries[28] = {
5
+ {"Display dataverses defined by Analytics service",
6
+ 50,
7
+ "{\"statement\":\"SELECT * FROM Metadata.`Dataverse`\"}"},
8
+
9
+ {"Tell analytics service to shadow the data from beer-sample bucket using breweries dataset.",
10
+ 84,
11
+ "{\"statement\":\"CREATE DATASET breweries ON `beer-sample` WHERE `type` = \\\"brewery\\\"\"}"},
12
+
13
+ {"Tell analytics service to shadow the data from beer-sample bucket using beers dataset.",
14
+ 77,
15
+ "{\"statement\":\"CREATE DATASET beers ON `beer-sample` WHERE `type` = \\\"beer\\\"\"}"},
16
+
17
+ {"Initiate the shadowing relationship of datasets to the data in Couchbase Server",
18
+ 34,
19
+ "{\"statement\":\"CONNECT LINK Local\"}"},
20
+
21
+ {"List populated datasets",
22
+ 129,
23
+ "{\"statement\":\"SELECT ds.BucketName, ds.DatasetName, ds.`Filter` FROM Metadata.`Dataset` ds WHERE ds.DataverseName = \\\"Default\\\"\"}"},
24
+
25
+ {"Ask Analytics the number of breweries",
26
+ 52,
27
+ "{\"statement\":\"SELECT VALUE COUNT(*) FROM breweries\"}"},
28
+
29
+ {"Retrieve first brewery, ordered by name",
30
+ 75,
31
+ "{\"statement\":\"SELECT * FROM breweries ORDER BY name LIMIT 1\",\"pretty\":true}"},
32
+
33
+ {"Find a particular brewery based on its Couchbase Server key",
34
+ 118,
35
+ "{\"statement\":\"SELECT meta(bw) AS meta, bw AS data FROM breweries bw WHERE meta(bw).id = 'kona_brewing'\",\"pretty\":true}"},
36
+
37
+ {"Find the same brewery information but in a slightly simpler or cleaner way based only on the data",
38
+ 94,
39
+ "{\"statement\":\"SELECT VALUE bw FROM breweries bw WHERE bw.name = 'Kona Brewing'\",\"pretty\":true}"},
40
+
41
+ {"Find brewery by name, but return objects instead of values",
42
+ 88,
43
+ "{\"statement\":\"SELECT bw FROM breweries bw WHERE bw.name = 'Kona Brewing'\",\"pretty\":true}"},
44
+
45
+ {"Apply a range condition together with a string condition to select breweries",
46
+ 133,
47
+ "{\"statement\":\"SELECT VALUE bw FROM breweries bw WHERE bw.geo.lat > 60.0 AND bw.name LIKE '%Brewing%' ORDER BY bw.name\",\"pretty\":true}"},
48
+
49
+ {"Fetch list of all breweries paired with their associated beers, with the list enumerating the brewery name and the beer name for each such pair, while also limiting the answer set size to at most 3 results.",
50
+ 153,
51
+ "{\"statement\":\"SELECT bw.name AS brewer, br.name AS beer FROM breweries bw, beers br WHERE br.brewery_id = meta(bw).id ORDER BY bw.name, br.name LIMIT 3\"}"},
52
+
53
+ {"Fetch list of all breweries paired with their associated beers, including all attributes, while also limiting the answer set size to at most 3 results.",
54
+ 134,
55
+ "{\"statement\":\"SELECT * FROM breweries bw, beers br WHERE br.brewery_id = meta(bw).id ORDER BY bw.name, br.name LIMIT 3\",\"pretty\":true}"},
56
+
57
+ {"Fetch list of all breweries paired with their associated beers, including all attributes, while also limiting the answer set size to at most 3 results. With ANSI JOINS!",
58
+ 135,
59
+ "{\"statement\":\"SELECT * FROM breweries bw JOIN beers br ON br.brewery_id = meta(bw).id ORDER BY bw.name, br.name LIMIT 3\",\"pretty\":true}"},
60
+
61
+ {"Fetch list of all breweries paired with their associated beers, including all attributes, while also limiting the answer set size to at most 3 results. Select values explicitly.",
62
+ 163,
63
+ "{\"statement\":\"SELECT VALUE {\\\"bw\\\": bw, \\\"br\\\": br} FROM breweries bw, beers br WHERE br.brewery_id = meta(bw).id ORDER BY bw.name, br.name LIMIT 3\",\"pretty\":true}"},
64
+
65
+ {"For each brewery produce an object that contains the brewery name along with a list of all of the brewery’s offered beer names and alcohol percentages",
66
+ 197,
67
+ "{\"statement\":\"SELECT bw.name AS brewer, (SELECT br.name, br.abv FROM beers br WHERE br.brewery_id = meta(bw).id ORDER BY br.name) AS beers FROM breweries bw ORDER BY bw.name LIMIT 2\",\"pretty\":true}"},
68
+
69
+ {"For each Arizona brewery get the brewery's name, location, and a list of competitors' names -- where competitors are other breweries that are geographically close to their location",
70
+ 319,
71
+ "{\"statement\":\"SELECT bw1.name AS brewer, bw1.geo AS location, (SELECT VALUE bw2.name FROM breweries bw2 WHERE bw2.name != bw1.name AND abs(bw1.geo.lat - bw2.geo.lat) <= 0.1 AND abs(bw2.geo.lon - bw1.geo.lon) <= 0.1) AS competitors FROM breweries bw1 WHERE bw1.state = 'Arizona' ORDER BY bw1.name LIMIT 3\",\"pretty\":true}"},
72
+
73
+ {"Find those breweries whose beers include at least one IPA and return the brewery’s name, phone number, and complete list of beer names and associated alcohol levels.",
74
+ 336,
75
+ "{\"statement\":\"WITH nested_breweries AS ( SELECT bw.name AS brewer, bw.phone, ( SELECT br.name, br.abv FROM beers br WHERE br.brewery_id = meta(bw).id ORDER BY br.name) AS beers FROM breweries bw) SELECT VALUE nb FROM nested_breweries nb WHERE (SOME b IN nb.beers SATISFIES b.name LIKE '%IPA%') ORDER BY nb.brewer LIMIT 2\",\"pretty\":true}"},
76
+
77
+ {"Find those breweries that only have seriously strong beers",
78
+ 359,
79
+ "{\"statement\":\"WITH nested_breweries AS ( SELECT bw.name AS brewer, bw.phone, ( SELECT br.name, br.abv FROM beers br WHERE br.brewery_id = meta(bw).id ORDER BY br.name) AS beers FROM breweries bw) SELECT VALUE nb FROM nested_breweries nb WHERE (EVERY b IN nb.beers SATISFIES b.abv >= 10) AND ARRAY_COUNT(nb.beers) > 0 ORDER BY nb.brewer LIMIT 5\",\"pretty\":true}"},
80
+
81
+ {"Compute the total number of beers in a SQL-like way",
82
+ 55,
83
+ "{\"statement\":\"SELECT COUNT(*) AS num_beers FROM beers\"}"},
84
+
85
+ {"Compute the total number of beers and return unwrapped value",
86
+ 50,
87
+ "{\"statement\":\"SELECT VALUE COUNT(b) FROM beers b\"}"},
88
+
89
+ {"Compute the total number of beers with explicit aggregate function",
90
+ 65,
91
+ "{\"statement\":\"SELECT VALUE ARRAY_COUNT((SELECT b FROM beers b))\"}"},
92
+
93
+ {"For each brewery that offers more than 30 beers, the following group-by or aggregate query reports the number of beers that it offers",
94
+ 140,
95
+ "{\"statement\":\"SELECT br.brewery_id, COUNT(*) AS num_beers FROM beers br GROUP BY br.brewery_id HAVING COUNT(*) > 30 ORDER BY COUNT(*) DESC\"}"},
96
+
97
+ {"For each brewery that offers more than 30 beers, the following group-by or aggregate query reports the number of beers that it offers. With a hash-based aggregation hint.",
98
+ 152,
99
+ "{\"statement\":\"SELECT br.brewery_id, COUNT(*) AS num_beers FROM beers br /*+ hash */ GROUP BY br.brewery_id HAVING COUNT(*) > 30 ORDER BY COUNT(*) DESC\"}"},
100
+
101
+ {"Return the top three breweries based on their numbers of offered beers. Also illustrate the use of multiple aggregate functions to compute various alcohol content statistics for their beers",
102
+ 236,
103
+ "{\"statement\":\"SELECT bw.name, COUNT(*) AS num_beers, AVG(br.abv) AS abv_avg, MIN(br.abv) AS abv_min, MAX(br.abv) AS abv_max FROM breweries bw, beers br WHERE br.brewery_id = meta(bw).id GROUP BY bw.name ORDER BY num_beers DESC LIMIT 3\"}"},
104
+
105
+ {"Find the same brewery information but specify name as parameter",
106
+ 108,
107
+ "{\"statement\":\"SELECT VALUE bw FROM breweries bw WHERE bw.name = $name\",\"$name\":\"Kona Brewing\",\"pretty\":true}"},
108
+
109
+ {"Find the same brewery information but specify name as parameter",
110
+ 105,
111
+ "{\"statement\":\"SELECT VALUE bw FROM breweries bw WHERE bw.name = ?\",\"args\":[\"Kona Brewing\"],\"pretty\":true}"},
112
+
113
+ {NULL, 0, NULL}};