diff --git a/samples/__snapshots__/filters.js b/samples/__snapshots__/filters.js new file mode 100644 index 000000000..a0c13a7e3 --- /dev/null +++ b/samples/__snapshots__/filters.js @@ -0,0 +1,501 @@ +exports['filters should filter with row regex 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.003 @1559347200000000 +Column Family cell_plan +\tdata_plan_01gb: true @1559347200000000 +\tdata_plan_01gb: false @1559174400000000 +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190401.002 @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + + +`; + +exports['filters should filter with cells per col 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.003 @1559347200000000 +Column Family cell_plan +\tdata_plan_01gb: true @1559347200000000 +\tdata_plan_01gb: false @1559174400000000 +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.004 @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190401.002 @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 0 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + + +`; + +exports['filters should filter with cells per row 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 0 @1559347200000000 + + +`; + +exports['filters should filter with cells per row offset 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tos_build: PQ2A.190405.003 @1559347200000000 +Column Family cell_plan +\tdata_plan_01gb: true @1559347200000000 +\tdata_plan_01gb: false @1559174400000000 +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tos_build: PQ2A.190405.004 @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tos_build: PQ2A.190406.000 @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tos_build: PQ2A.190401.002 @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tos_build: PQ2A.190406.000 @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + + +`; + +exports['filters should filter with col family regex 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.003 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.004 @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190401.002 @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 0 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 + + +`; + +exports['filters should filter with col qualifier regex 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 0 @1559347200000000 + + +`; + +exports['filters should filter with col range 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family cell_plan +\tdata_plan_01gb: true @1559347200000000 +\tdata_plan_01gb: false @1559174400000000 +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + + +`; + +exports['filters should filter with value range 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tos_build: PQ2A.190405.003 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tos_build: PQ2A.190405.004 @1559347200000000 + + +`; + +exports['filters should filter with value regex 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tos_build: PQ2A.190405.003 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tos_build: PQ2A.190405.004 @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tos_build: PQ2A.190406.000 @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tos_build: PQ2A.190401.002 @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tos_build: PQ2A.190406.000 @1559347200000000 + + +`; + +exports['filters should filter with timestamp range 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family cell_plan +\tdata_plan_01gb: false @1559174400000000 + + +`; + +exports['filters should filter with pass all 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.003 @1559347200000000 +Column Family cell_plan +\tdata_plan_01gb: true @1559347200000000 +\tdata_plan_01gb: false @1559174400000000 +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.004 @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190401.002 @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 0 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + + +`; + +exports['filters should filter with strip value 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: @1559347200000000 +\tconnected_wifi: @1559347200000000 +\tos_build: @1559347200000000 +Column Family cell_plan +\tdata_plan_01gb: @1559347200000000 +\tdata_plan_01gb: @1559174400000000 +\tdata_plan_05gb: @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: @1559347200000000 +\tconnected_wifi: @1559347200000000 +\tos_build: @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: @1559347200000000 +\tconnected_wifi: @1559347200000000 +\tos_build: @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: @1559347200000000 +\tconnected_wifi: @1559347200000000 +\tos_build: @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: @1559347200000000 +\tconnected_wifi: @1559347200000000 +\tos_build: @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: @1559347200000000 + + +`; + +exports['filters should filter with label 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 [labelled] +\tconnected_wifi: 1 @1559347200000000 [labelled] +\tos_build: PQ2A.190405.003 @1559347200000000 [labelled] +Column Family cell_plan +\tdata_plan_01gb: true @1559347200000000 [labelled] +\tdata_plan_01gb: false @1559174400000000 [labelled] +\tdata_plan_05gb: true @1559347200000000 [labelled] + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 [labelled] +\tconnected_wifi: 1 @1559347200000000 [labelled] +\tos_build: PQ2A.190405.004 @1559347200000000 [labelled] +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 [labelled] + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 [labelled] +\tconnected_wifi: 1 @1559347200000000 [labelled] +\tos_build: PQ2A.190406.000 @1559347200000000 [labelled] +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 [labelled] + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 [labelled] +\tconnected_wifi: 1 @1559347200000000 [labelled] +\tos_build: PQ2A.190401.002 @1559347200000000 [labelled] +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 [labelled] + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 [labelled] +\tconnected_wifi: 0 @1559347200000000 [labelled] +\tos_build: PQ2A.190406.000 @1559347200000000 [labelled] +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 [labelled] + + +`; + +exports['filters should filter with chain 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family cell_plan +\tdata_plan_01gb: true @1559347200000000 +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + + +`; + +exports['filters should filter with interleave 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tos_build: PQ2A.190405.003 @1559347200000000 +Column Family cell_plan +\tdata_plan_01gb: true @1559347200000000 +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tos_build: PQ2A.190405.004 @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tos_build: PQ2A.190406.000 @1559347200000000 +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tos_build: PQ2A.190401.002 @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tos_build: PQ2A.190406.000 @1559347200000000 +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 + + +`; + +exports['filters should filter with condition 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 [filtered-out] +\tconnected_wifi: 1 @1559347200000000 [filtered-out] +\tos_build: PQ2A.190405.003 @1559347200000000 [filtered-out] +Column Family cell_plan +\tdata_plan_01gb: true @1559347200000000 [filtered-out] +\tdata_plan_01gb: false @1559174400000000 [filtered-out] +\tdata_plan_05gb: true @1559347200000000 [filtered-out] + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 [filtered-out] +\tconnected_wifi: 1 @1559347200000000 [filtered-out] +\tos_build: PQ2A.190405.004 @1559347200000000 [filtered-out] +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 [filtered-out] + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 [filtered-out] +\tconnected_wifi: 1 @1559347200000000 [filtered-out] +\tos_build: PQ2A.190406.000 @1559347200000000 [filtered-out] +Column Family cell_plan +\tdata_plan_05gb: true @1559347200000000 [filtered-out] + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 [passed-filter] +\tconnected_wifi: 1 @1559347200000000 [passed-filter] +\tos_build: PQ2A.190401.002 @1559347200000000 [passed-filter] +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 [passed-filter] + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 [passed-filter] +\tconnected_wifi: 0 @1559347200000000 [passed-filter] +\tos_build: PQ2A.190406.000 @1559347200000000 [passed-filter] +Column Family cell_plan +\tdata_plan_10gb: true @1559347200000000 [passed-filter] + + +`; diff --git a/samples/__snapshots__/reads.js b/samples/__snapshots__/reads.js new file mode 100644 index 000000000..0234b320b --- /dev/null +++ b/samples/__snapshots__/reads.js @@ -0,0 +1,147 @@ +exports['reads should read one row 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.003 @1559347200000000 + + +`; + +exports['reads should read part of one row 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tos_build: PQ2A.190405.003 @1559347200000000 + + +`; + +exports['reads should read multiple rows 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.003 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.004 @1559347200000000 + + +`; + +exports['reads should read a range of rows 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.003 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.004 @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 + + +`; + +exports['reads should read multiple ranges of rows 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.003 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.004 @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190401.002 @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 0 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 + + +`; + +exports['reads should read using a row prefix 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.003 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190405.004 @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tconnected_cell: 0 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 1 @1559347200000000 +\tos_build: PQ2A.190401.002 @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tconnected_cell: 1 @1559347200000000 +\tconnected_wifi: 0 @1559347200000000 +\tos_build: PQ2A.190406.000 @1559347200000000 + + +`; + +exports['reads should read with a filter 1'] = ` +Reading data for phone#4c410523#20190501: +Column Family stats_summary +\tos_build: PQ2A.190405.003 @1559347200000000 + +Reading data for phone#4c410523#20190502: +Column Family stats_summary +\tos_build: PQ2A.190405.004 @1559347200000000 + +Reading data for phone#4c410523#20190505: +Column Family stats_summary +\tos_build: PQ2A.190406.000 @1559347200000000 + +Reading data for phone#5c10102#20190501: +Column Family stats_summary +\tos_build: PQ2A.190401.002 @1559347200000000 + +Reading data for phone#5c10102#20190502: +Column Family stats_summary +\tos_build: PQ2A.190406.000 @1559347200000000 + + +`; diff --git a/samples/filterSnippets.js b/samples/filterSnippets.js new file mode 100644 index 000000000..dec19e9ef --- /dev/null +++ b/samples/filterSnippets.js @@ -0,0 +1,379 @@ +// Copyright 2019 Google LLC +// +// Licensed 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. + +'use strict'; + +function main( + instanceId = 'YOUR_INSTANCE_ID', + tableId = 'YOUR_TABLE_ID', + filterType = 'filterRowSample' +) { + // [START bigtable_filters_limit_row_sample] + // [START bigtable_filters_limit_row_regex] + // [START bigtable_filters_limit_cells_per_col] + // [START bigtable_filters_limit_cells_per_row] + // [START bigtable_filters_limit_cells_per_row_offset] + // [START bigtable_filters_limit_col_family_regex] + // [START bigtable_filters_limit_col_qualifier_regex] + // [START bigtable_filters_limit_col_range] + // [START bigtable_filters_limit_value_range] + // [START bigtable_filters_limit_value_regex] + // [START bigtable_filters_limit_timestamp_range] + // [START bigtable_filters_limit_block_all] + // [START bigtable_filters_limit_pass_all] + // [START bigtable_filters_modify_strip_value] + // [START bigtable_filters_modify_apply_label] + // [START bigtable_filters_composing_chain] + // [START bigtable_filters_composing_interleave] + // [START bigtable_filters_composing_condition] + const {Bigtable} = require('@google-cloud/bigtable'); + const bigtable = Bigtable(); + + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const instanceId = 'YOUR_INSTANCE_ID'; + // const tableId = 'YOUR_TABLE_ID'; + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [END bigtable_filters_limit_row_sample] + // [END bigtable_filters_limit_row_regex] + // [END bigtable_filters_limit_cells_per_col] + // [END bigtable_filters_limit_cells_per_row] + // [END bigtable_filters_limit_cells_per_row_offset] + // [END bigtable_filters_limit_col_family_regex] + // [END bigtable_filters_limit_col_qualifier_regex] + // [END bigtable_filters_limit_col_range] + // [END bigtable_filters_limit_value_range] + // [END bigtable_filters_limit_value_regex] + // [END bigtable_filters_limit_timestamp_range] + // [END bigtable_filters_limit_block_all] + // [END bigtable_filters_limit_pass_all] + // [END bigtable_filters_modify_strip_value] + // [END bigtable_filters_modify_apply_label] + // [END bigtable_filters_composing_chain] + // [END bigtable_filters_composing_interleave] + // [END bigtable_filters_composing_condition] + + switch (filterType) { + case 'filterRowSample': { + // [START bigtable_filters_limit_row_sample] + const filter = { + row: { + sample: 0.75, + }, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_row_sample] + break; + } + + case 'filterRowRegex': { + // [START bigtable_filters_limit_row_regex] + const filter = { + row: /.*#20190501$/, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_row_regex] + break; + } + + case 'filterCellsPerCol': { + // [START bigtable_filters_limit_cells_per_col] + const filter = { + column: { + cellLimit: 2, + }, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_cells_per_col] + break; + } + + case 'filterCellsPerRow': { + // [START bigtable_filters_limit_cells_per_row] + const filter = { + row: { + cellLimit: 2, + }, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_cells_per_row] + break; + } + + case 'filterCellsPerRowOffset': { + // [START bigtable_filters_limit_cells_per_row_offset] + const filter = { + row: { + cellOffset: 2, + }, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_cells_per_row_offset] + break; + } + + case 'filterColFamilyRegex': { + // [START bigtable_filters_limit_col_family_regex] + const filter = { + family: /stats_.*$/, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_col_family_regex] + break; + } + + case 'filterColQualifierRegex': { + // [START bigtable_filters_limit_col_qualifier_regex] + const filter = { + column: /connected_.*$/, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_col_qualifier_regex] + break; + } + + case 'filterColRange': { + // [START bigtable_filters_limit_col_range] + const filter = { + column: { + family: 'cell_plan', + start: 'data_plan_01gb', + end: { + value: 'data_plan_10gb', + inclusive: false, + }, + }, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_col_range] + break; + } + + case 'filterValueRange': { + // [START bigtable_filters_limit_value_range] + const filter = { + value: { + start: 'PQ2A.190405', + end: 'PQ2A.190406', + }, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_value_range] + break; + } + + case 'filterValueRegex': { + // [START bigtable_filters_limit_value_regex] + const filter = { + value: /PQ2A.*$/, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_value_regex] + break; + } + + case 'filterTimestampRange': { + // [START bigtable_filters_limit_timestamp_range] + const start = 0; + const end = new Date(2019, 5, 1); + end.setUTCHours(0); + const filter = { + time: { + start, + end, + }, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_timestamp_range] + break; + } + + case 'filterBlockAll': { + // [START bigtable_filters_limit_block_all] + const filter = { + all: false, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_block_all] + break; + } + + case 'filterPassAll': { + // [START bigtable_filters_limit_pass_all] + const filter = { + all: true, + }; + readWithFilter(filter); + // [END bigtable_filters_limit_pass_all] + break; + } + + case 'filterStripValue': { + // [START bigtable_filters_modify_strip_value] + const filter = { + value: { + strip: true, + }, + }; + readWithFilter(filter); + // [END bigtable_filters_modify_strip_value] + break; + } + + case 'filterApplyLabel': { + // [START bigtable_filters_modify_apply_label] + const filter = { + label: 'labelled', + }; + readWithFilter(filter); + // [END bigtable_filters_modify_apply_label] + break; + } + + case 'filterChain': { + // [START bigtable_filters_composing_chain] + const filter = [ + { + column: { + cellLimit: 1, + }, + }, + { + family: 'cell_plan', + }, + ]; + readWithFilter(filter); + // [END bigtable_filters_composing_chain] + break; + } + + case 'filterInterleave': { + // [START bigtable_filters_composing_interleave] + const filter = { + interleave: [ + { + value: 'true', + }, + {column: 'os_build'}, + ], + }; + readWithFilter(filter); + // [END bigtable_filters_composing_interleave] + break; + } + + case 'filterCondition': { + // [START bigtable_filters_composing_condition] + const filter = { + condition: { + test: [ + {column: 'data_plan_10gb'}, + { + value: 'true', + }, + ], + pass: { + label: 'passed-filter', + }, + fail: { + label: 'filtered-out', + }, + }, + }; + readWithFilter(filter); + // [END bigtable_filters_composing_condition] + break; + } + } + + // [START bigtable_filters_limit_row_sample] + // [START bigtable_filters_limit_row_regex] + // [START bigtable_filters_limit_cells_per_col] + // [START bigtable_filters_limit_cells_per_row] + // [START bigtable_filters_limit_cells_per_row_offset] + // [START bigtable_filters_limit_col_family_regex] + // [START bigtable_filters_limit_col_qualifier_regex] + // [START bigtable_filters_limit_col_range] + // [START bigtable_filters_limit_value_range] + // [START bigtable_filters_limit_value_regex] + // [START bigtable_filters_limit_timestamp_range] + // [START bigtable_filters_limit_block_all] + // [START bigtable_filters_limit_pass_all] + // [START bigtable_filters_modify_strip_value] + // [START bigtable_filters_modify_apply_label] + // [START bigtable_filters_composing_chain] + // [START bigtable_filters_composing_interleave] + // [START bigtable_filters_composing_condition] + async function readWithFilter(filter) { + await table + .createReadStream({ + filter, + }) + .on('error', err => { + // Handle the error. + console.log(err); + }) + .on('data', row => printRow(row.id, row.data)) + .on('end', () => { + // All rows retrieved. + }); + } + + function printRow(rowkey, rowData) { + console.log(`Reading data for ${rowkey}:`); + + for (const columnFamily of Object.keys(rowData)) { + const columnFamilyData = rowData[columnFamily]; + console.log(`Column Family ${columnFamily}`); + + for (const columnQualifier of Object.keys(columnFamilyData)) { + const col = columnFamilyData[columnQualifier]; + + for (const cell of col) { + const labels = cell.labels.length + ? ` [${cell.labels.join(',')}]` + : ''; + console.log( + `\t${columnQualifier}: ${cell.value} @${cell.timestamp}${labels}` + ); + } + } + } + console.log(); + } + + // [END bigtable_filters_limit_row_sample] + // [END bigtable_filters_limit_row_regex] + // [END bigtable_filters_limit_cells_per_col] + // [END bigtable_filters_limit_cells_per_row] + // [END bigtable_filters_limit_cells_per_row_offset] + // [END bigtable_filters_limit_col_family_regex] + // [END bigtable_filters_limit_col_qualifier_regex] + // [END bigtable_filters_limit_col_range] + // [END bigtable_filters_limit_value_range] + // [END bigtable_filters_limit_value_regex] + // [END bigtable_filters_limit_timestamp_range] + // [END bigtable_filters_limit_block_all] + // [END bigtable_filters_limit_pass_all] + // [END bigtable_filters_modify_strip_value] + // [END bigtable_filters_modify_apply_label] + // [END bigtable_filters_composing_chain] + // [END bigtable_filters_composing_interleave] + // [END bigtable_filters_composing_condition] +} + +main(...process.argv.slice(2)); diff --git a/samples/package.json b/samples/package.json index a0d288b58..13b428db5 100644 --- a/samples/package.json +++ b/samples/package.json @@ -20,9 +20,11 @@ "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.0.0", "chai": "^4.2.0", - "mocha": "^6.0.0" + "mocha": "^6.0.0", + "snap-shot-it": "^7.9.1" }, "scripts": { - "test": "mocha --timeout=60000" + "test": "mocha --timeout=60000", + "test:snap": "SNAPSHOT_UPDATE=1 npm test" } } diff --git a/samples/readSnippets.js b/samples/readSnippets.js new file mode 100644 index 000000000..d925bdd7d --- /dev/null +++ b/samples/readSnippets.js @@ -0,0 +1,212 @@ +// Copyright 2019 Google LLC +// +// Licensed 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. + +'use strict'; + +async function main( + instanceId = 'YOUR_INSTANCE_ID', + tableId = 'YOUR_TABLE_ID', + readType = 'readRow' +) { + // [START bigtable_reads_row] + // [START bigtable_reads_row_partial] + // [START bigtable_reads_rows] + // [START bigtable_reads_row_range] + // [START bigtable_reads_row_ranges] + // [START bigtable_reads_prefix] + // [START bigtable_reads_filter] + const {Bigtable} = require('@google-cloud/bigtable'); + const bigtable = Bigtable(); + + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const instanceId = 'YOUR_INSTANCE_ID'; + // const tableId = 'YOUR_TABLE_ID'; + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + // [END bigtable_reads_row] + // [END bigtable_reads_row_partial] + // [END bigtable_reads_rows] + // [END bigtable_reads_row_range] + // [END bigtable_reads_row_ranges] + // [END bigtable_reads_prefix] + // [END bigtable_reads_filter] + switch (readType) { + // [START bigtable_reads_row] + case 'readRow': { + const rowkey = 'phone#4c410523#20190501'; + + const [row] = await table.row(rowkey).get(); + printRow(rowkey, row.data); + // [END bigtable_reads_row] + break; + } + + // [START bigtable_reads_row_partial] + case 'readRowPartial': { + const COLUMN_FAMILY = 'stats_summary'; + const COLUMN_QUALIFIER = 'os_build'; + const rowkey = 'phone#4c410523#20190501'; + + const [row] = await table + .row(rowkey) + .get([`${COLUMN_FAMILY}:${COLUMN_QUALIFIER}`]); + + printRow(rowkey, row); + // [END bigtable_reads_row_partial] + break; + } + + // [START bigtable_reads_rows] + case 'readRows': { + const rowKeys = ['phone#4c410523#20190501', 'phone#4c410523#20190502']; + const [rows] = await table.getRows({keys: rowKeys}); + rows.forEach(row => printRow(row.id, row.data)); + // [END bigtable_reads_rows] + break; + } + + // [START bigtable_reads_row_range] + case 'readRowRange': { + const start = 'phone#4c410523#20190501'; + const end = 'phone#4c410523#201906201'; + + await table + .createReadStream({ + start, + end, + }) + .on('error', err => { + // Handle the error. + console.log(err); + }) + .on('data', row => printRow(row.id, row.data)) + .on('end', () => { + // All rows retrieved. + }); + // [END bigtable_reads_row_range] + break; + } + + // [START bigtable_reads_row_ranges] + case 'readRowRanges': { + await table + .createReadStream({ + ranges: [ + { + start: 'phone#4c410523#20190501', + end: 'phone#4c410523#20190601', + }, + { + start: 'phone#5c10102#20190501', + end: 'phone#5c10102#20190601', + }, + ], + }) + .on('error', err => { + // Handle the error. + console.log(err); + }) + .on('data', row => printRow(row.id, row.data)) + .on('end', () => { + // All rows retrieved. + }); + // [END bigtable_reads_row_ranges] + break; + } + + // [START bigtable_reads_prefix] + case 'readPrefix': { + const prefix = 'phone#'; + + await table + .createReadStream({ + prefix, + }) + .on('error', err => { + // Handle the error. + console.log(err); + }) + .on('data', row => printRow(row.id, row.data)) + .on('end', () => { + // All rows retrieved. + }); + // [END bigtable_reads_prefix] + break; + } + + // [START bigtable_reads_filter] + case 'readFilter': { + const filter = { + value: /PQ2A.*$/, + }; + + await table + .createReadStream({ + filter, + }) + .on('error', err => { + // Handle the error. + console.log(err); + }) + .on('data', row => printRow(row.id, row.data)) + .on('end', () => { + // All rows retrieved. + }); + // [END bigtable_reads_filter] + break; + } + } + + // [START bigtable_reads_row] + // [START bigtable_reads_row_partial] + // [START bigtable_reads_rows] + // [START bigtable_reads_row_range] + // [START bigtable_reads_row_ranges] + // [START bigtable_reads_prefix] + // [START bigtable_reads_filter] + function printRow(rowkey, rowData) { + console.log(`Reading data for ${rowkey}:`); + + for (const columnFamily of Object.keys(rowData)) { + const columnFamilyData = rowData[columnFamily]; + console.log(`Column Family ${columnFamily}`); + + for (const columnQualifier of Object.keys(columnFamilyData)) { + const col = columnFamilyData[columnQualifier]; + + for (const cell of col) { + const labels = cell.labels.length + ? ` [${cell.labels.join(',')}]` + : ''; + console.log( + `\t${columnQualifier}: ${cell.value} @${cell.timestamp}${labels}` + ); + } + } + } + console.log(); + } + + // [END bigtable_reads_row] + // [END bigtable_reads_row_partial] + // [END bigtable_reads_rows] + // [END bigtable_reads_row_range] + // [END bigtable_reads_row_ranges] + // [END bigtable_reads_prefix] + // [END bigtable_reads_filter] +} + +main(...process.argv.slice(2)); diff --git a/samples/test/filters.js b/samples/test/filters.js new file mode 100644 index 000000000..b1b28cad4 --- /dev/null +++ b/samples/test/filters.js @@ -0,0 +1,334 @@ +// Copyright 2019 Google LLC +// +// Licensed 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. + +'use strict'; +const uuid = require(`uuid`); +const snapshot = require('snap-shot-it'); + +const {assert} = require('chai'); +const cp = require('child_process'); +const {Bigtable} = require('@google-cloud/bigtable'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const INSTANCE_ID = `nodejs-bigtable-samples-keepme`; +const TABLE_ID = `mobile-time-series-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules + +describe('filters', async () => { + const bigtable = Bigtable(); + const instance = bigtable.instance(INSTANCE_ID); + let table; + const TIMESTAMP = new Date(2019, 5, 1); + TIMESTAMP.setUTCHours(0); + const TIMESTAMP_OLDER = new Date(2019, 4, 30); + TIMESTAMP_OLDER.setUTCHours(0); + + before(async () => { + table = instance.table(TABLE_ID); + + await table.create().catch(console.error); + await table.createFamily('stats_summary').catch(console.error); + await table.createFamily('cell_plan').catch(console.error); + + const rowsToInsert = [ + { + key: 'phone#4c410523#20190501', + data: { + cell_plan: { + data_plan_01gb: { + value: 'false', + timestamp: TIMESTAMP_OLDER, + }, + }, + }, + }, + { + key: 'phone#4c410523#20190501', + data: { + stats_summary: { + connected_cell: { + value: 1, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 1, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190405.003', + timestamp: TIMESTAMP, + }, + }, + cell_plan: { + data_plan_01gb: { + value: 'true', + timestamp: TIMESTAMP, + }, + data_plan_05gb: { + value: 'true', + timestamp: TIMESTAMP, + }, + }, + }, + }, + { + key: 'phone#4c410523#20190502', + data: { + stats_summary: { + connected_cell: { + value: 1, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 1, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190405.004', + timestamp: TIMESTAMP, + }, + }, + cell_plan: { + data_plan_05gb: { + value: 'true', + timestamp: TIMESTAMP, + }, + }, + }, + }, + { + key: 'phone#4c410523#20190505', + data: { + stats_summary: { + connected_cell: { + value: 0, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 1, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190406.000', + timestamp: TIMESTAMP, + }, + }, + cell_plan: { + data_plan_05gb: { + value: 'true', + timestamp: TIMESTAMP, + }, + }, + }, + }, + { + key: 'phone#5c10102#20190501', + data: { + stats_summary: { + connected_cell: { + value: 1, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 1, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190401.002', + timestamp: TIMESTAMP, + }, + }, + cell_plan: { + data_plan_10gb: { + value: 'true', + timestamp: TIMESTAMP, + }, + }, + }, + }, + { + key: 'phone#5c10102#20190502', + data: { + stats_summary: { + connected_cell: { + value: 1, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 0, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190406.000', + timestamp: TIMESTAMP, + }, + }, + cell_plan: { + data_plan_10gb: { + value: 'true', + timestamp: TIMESTAMP, + }, + }, + }, + }, + ]; + + await table.insert(rowsToInsert).catch(console.error); + }); + + after(async () => { + await table.delete().catch(console.error); + }); + + it('should filter with row sample', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterRowSample` + ); + console.log('stdout', stdout); + assert.include(stdout, 'Reading data for'); + }); + + it('should filter with row regex', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterRowRegex` + ); + + snapshot(stdout); + }); + + it('should filter with cells per col', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterCellsPerCol` + ); + + snapshot(stdout); + }); + + it('should filter with cells per row', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterCellsPerRow` + ); + + snapshot(stdout); + }); + + it('should filter with cells per row offset', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterCellsPerRowOffset` + ); + + snapshot(stdout); + }); + + it('should filter with col family regex', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterColFamilyRegex` + ); + + snapshot(stdout); + }); + + it('should filter with col qualifier regex', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterColQualifierRegex` + ); + + snapshot(stdout); + }); + + it('should filter with col range', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterColRange` + ); + + snapshot(stdout); + }); + + it('should filter with value range', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterValueRange` + ); + + snapshot(stdout); + }); + + it('should filter with value regex', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterValueRegex` + ); + + snapshot(stdout); + }); + + it('should filter with timestamp range', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterTimestampRange` + ); + + snapshot(stdout); + }); + + it('should filter with block all', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterBlockAll` + ); + const result = ``; + assert.equal(stdout, result); + }); + + it('should filter with pass all', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterPassAll` + ); + + snapshot(stdout); + }); + + it('should filter with strip value', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterStripValue` + ); + + snapshot(stdout); + }); + + it('should filter with label', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterApplyLabel` + ); + + snapshot(stdout); + }); + it('should filter with chain', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterChain` + ); + + snapshot(stdout); + }); + it('should filter with interleave', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterInterleave` + ); + + snapshot(stdout); + }); + it('should filter with condition', async () => { + const stdout = execSync( + `node filterSnippets ${INSTANCE_ID} ${TABLE_ID} filterCondition` + ); + + snapshot(stdout); + }); +}); diff --git a/samples/test/reads.js b/samples/test/reads.js new file mode 100644 index 000000000..30566480d --- /dev/null +++ b/samples/test/reads.js @@ -0,0 +1,192 @@ +// Copyright 2019 Google LLC +// +// Licensed 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. + +'use strict'; +const uuid = require(`uuid`); +const snapshot = require('snap-shot-it'); + +const cp = require('child_process'); +const {Bigtable} = require('@google-cloud/bigtable'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const INSTANCE_ID = `nodejs-bigtable-samples-keepme`; +const TABLE_ID = `mobile-time-series-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules + +describe('reads', async () => { + const bigtable = Bigtable(); + const instance = bigtable.instance(INSTANCE_ID); + let table; + const TIMESTAMP = new Date(2019, 5, 1); + TIMESTAMP.setUTCHours(0); + + before(async () => { + table = instance.table(TABLE_ID); + + await table.create().catch(console.error); + await table.createFamily('stats_summary').catch(console.error); + + const rowsToInsert = [ + { + key: 'phone#4c410523#20190501', + data: { + stats_summary: { + connected_cell: { + value: 1, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 1, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190405.003', + timestamp: TIMESTAMP, + }, + }, + }, + }, + { + key: 'phone#4c410523#20190502', + data: { + stats_summary: { + connected_cell: { + value: 1, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 1, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190405.004', + timestamp: TIMESTAMP, + }, + }, + }, + }, + { + key: 'phone#4c410523#20190505', + data: { + stats_summary: { + connected_cell: { + value: 0, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 1, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190406.000', + timestamp: TIMESTAMP, + }, + }, + }, + }, + { + key: 'phone#5c10102#20190501', + data: { + stats_summary: { + connected_cell: { + value: 1, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 1, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190401.002', + timestamp: TIMESTAMP, + }, + }, + }, + }, + { + key: 'phone#5c10102#20190502', + data: { + stats_summary: { + connected_cell: { + value: 1, + timestamp: TIMESTAMP, + }, + connected_wifi: { + value: 0, + timestamp: TIMESTAMP, + }, + os_build: { + value: 'PQ2A.190406.000', + timestamp: TIMESTAMP, + }, + }, + }, + }, + ]; + + await table.insert(rowsToInsert).catch(console.error); + }); + + after(async () => { + await table.delete().catch(console.error); + }); + + it('should read one row', async () => { + const stdout = execSync(`node readSnippets ${INSTANCE_ID} ${TABLE_ID}`); + snapshot(stdout); + }); + + it('should read part of one row', async () => { + const stdout = execSync( + `node readSnippets ${INSTANCE_ID} ${TABLE_ID} readRowPartial` + ); + snapshot(stdout); + }); + + it('should read multiple rows', async () => { + const stdout = execSync( + `node readSnippets ${INSTANCE_ID} ${TABLE_ID} readRows` + ); + snapshot(stdout); + }); + + it('should read a range of rows', async () => { + const stdout = execSync( + `node readSnippets ${INSTANCE_ID} ${TABLE_ID} readRowRange` + ); + snapshot(stdout); + }); + + it('should read multiple ranges of rows', async () => { + const stdout = execSync( + `node readSnippets ${INSTANCE_ID} ${TABLE_ID} readRowRanges` + ); + snapshot(stdout); + }); + + it('should read using a row prefix', async () => { + const stdout = execSync( + `node readSnippets ${INSTANCE_ID} ${TABLE_ID} readPrefix` + ); + snapshot(stdout); + }); + + it('should read with a filter', async () => { + const stdout = execSync( + `node readSnippets ${INSTANCE_ID} ${TABLE_ID} readFilter` + ); + + snapshot(stdout); + }); +});