# JuliaDB: GroupViews

**URL:** https://discourse.julialang.org/t/juliadb-groupviews/20045
**Category:** Data
**Created:** [January 24, 2019, 5:10pm UTC](https://discourse.julialang.org/t/juliadb-groupviews/20045 "2019-01-24T17:10:42Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)
#### Post date: [January 24, 2019, 5:10pm UTC](https://discourse.julialang.org/t/juliadb-groupviews/20045/1 "2019-01-24T17:10:42Z")

</div>

I’ve found it particularly useful to view JuliaDB tables by chunks (denoted either by their primary keys, or a subset of the indexing key). Is there any plan to implement anything like the following into the library(whether in IndexedTables or JuliaDB)?

```julia
struct GroupViews
    jdb
    keyview
    key::Union{Tuple, Array}
    length::Int
end

GroupViews(jdb) = GroupViews(jdb, select( jdb, jdb.pkey ), jdb.pkey, length( jdb ) )
GroupViews(jdb, key) = GroupViews(jdb, select(jdb, key), key, length( jdb ) )

function Base.iterate( iter::GroupViews, state = ( 1, iter.keyview[1] ) )
    index, lastchunkkey = state
    if index == iter.length
        return( nothing )  
    end
    
    inchunk = true
    lastindex = index
    
    while inchunk
        index += 1
        if index == iter.length
            break  
        end
        inchunk = all( values(iter.keyview[index]) .== values(lastchunkkey) )
    end
    return( ( iter.jdb[(lastindex):(index - 1)], ((lastindex),(index - 1))), #Return value(jdb view, (index_i, index_f))
            ( index , iter.keyview[index] ) )#State
end

```
