aggregate-functions


Querying customDimensions in Google Bigquery


Can someone explain how to query customDimensions in bigquery?
My query works with a simple where clause i.e.
SELECT COUNT(DISTINCT fullVisitorId)
FROM GA_SESSION
WHERE hits.customDimensions.index = 4
AND hits.customDimensions.value = 'variable1'
AND hits.page.pagePath LIKE '%something%';
However now when I try to do an aggregates, or if I try EXACT_COUNT_DISTINCT without a group by, I get an error i.e.
SELECT date, COUNT(DISTINCT fullVisitorId)
FROM GA_SESSION
WHERE hits.customDimensions.index = 4
AND hits.customDimensions.value = 'variable1'
AND hits.page.pagePath LIKE '%something%'
group by date
Error is :
Query Failed
Error: Cannot query the cross product of repeated fields customDimensions.index and hits.customDimensions.index.
Those are repeated fields, and you need to FLATTEN them in order to query.
FLATTEN converts a repeated field into an optional field. Given one record with many values for a repeated field, FLATTEN unrolls it into many records, one record for each value of the (formerly) repeated field; any non-repeated fields become duplicated to fill out each of the new records formed. FLATTEN removes one level of nesting.
Read more about FLATTEN
You need to rewrite your query into:
SELECT .... FROM FLATTEN(FLATTEN(GA_SESSION,customDimensions),hits.customDimensions)

Related Links

Creating percentile_cont as aggregate function in Vertica
Create Expression in Report Builder 3.0 Report to sum a column
SAP Hana - STRING_AGG issue with ORDER BY CLAUSE
rrdtool does not keep max
Tableau Aggregate Percentage
use aggregates (min, max, avg) in CONSTRUCT query [duplicate]
R: transposing and aggregating columns
SQL Query Aggregate Error
Usage of aggregate functions in MarkLogic
Querying customDimensions in Google Bigquery
NHibernate - QueryOver criteria appearing in Where instead in Having clause, error
Howto aggregate on full data set in Spring Batch jobs?
Creating an aggregate function fails
Necessity of declaration of function in c and cpp
Calculate window average in tableau
Complexity asymptotic relation (theta, Big O, little o, Big Omega, little omega) between functions

Categories

HOME
excel-formula
gcc
msbuild
domain-driven-design
cluster-analysis
bigtable
gaussian
where
perl6
autocad
pip
subprocess
soap-client
google-my-business-api
kairosdb
tracking
derby
repeater
webseal
background-image
airbnb
md2
audio-streaming
computation-theory
webgl-earth
prepros
chartist.js
libxml2
units-of-measurement
ios-autolayout
keil
kubectl
eclipse-jdt
openvms
mkdir
repeat
collation
api-key
mef
google-chrome-storage
stream-socket-client
monaca
skype-bots
multivalue
openidm
wink
richtext
dynatable
trusted-computing
apache-commons-cli
sharing
netlink
phpdesigner
pebble-js
innertext
cexception
methodology
newlib
gnu-sort
jain-sip
om
autoscaling
joomla3.3
teamwork
ultraedit
attiny
xmla
touch-typing
random-access
nsurlrequest
pytz
javacompiler
disabled-control
debuggervisualizer
hotlinking
enquire.js
pthreads-win32
logo-lang
mysql-error-1146
code-complete
asp.net-4.0
junction-table
openafs
dancer
nsscrollview
reflexil
umfpack
symfony-1.2
method-call
jqtransform
subdirectories
iphone-maps
web-widget
ffdshow
onresize
j++
office-2003
moores-law

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App