nunique
Syntax
nunique(X, [ignoreNull=false])
Arguments
X is a vector/array vector or a tuple composed of multiple vectors with same length.
ignoreNull (optional) is a Boolean value. If set to true, only non-NULL elements will be included in the calculation. The default value is false. Note that if X is a tuple or array vector, ignoreNull must be set to false.
Details
If X is a vector/array vector, return the number of unique elements in X.
If X is a tuple, elements of each vector at the same position forms a key, and this function returns the number of unique keys.
Examples
v = [1,3,1,-6,NULL,2,NULL,1];
nunique(v);
// output: 5
// set ignoreNull=true
nunique(v,true);
// output: 4
t=table(1 2 4 8 4 2 7 1 as id, 10 20 40 80 40 20 70 10 as val);
select nunique([id,val]) from t;
nunique |
---|
5 |
dbName = "dfs://testdb"
if(existsDatabase(dbName)){
dropDatabase(dbName)
}
db=database("dfs://testdb", VALUE, 2012.01.11..2012.01.29)
n=100
t=table(take(2012.01.11..2012.01.29, n) as date, symbol(take("A"+string(21..60), n)) as sym, take(100, n) as val)
pt=db.createPartitionedTable(t, `pt, `date).append!(t)
select nunique(date) from pt group by sym
dbName = "dfs://testdb"
if(existsDatabase(dbName)){
dropDatabase(dbName)
}
db=database("dfs://testdb", VALUE, 2012.01.11..2012.01.29)
n=100
t=table(take(2012.01.11..2012.01.29, n) as date, symbol(take("A"+string(21..60), n)) as sym, take(100, n) as val)
pt=db.createPartitionedTable(t, `pt, `date).append!(t)
select nunique(date) from pt group by sym