A Saturday 21 June 2008, Erik Demming escrigué:
> Hi,
>
> what is the best way to create a Table with nested array columns?
>
> I have a 1:N relationship in a data structure and would like to store
> the dependent data in the same row, because at each lookup of a child
> row I also need the parent data and vice versa.
>
> Best would be, if I could create something like this:
>
> class Child(IsDescription):
>     id = IntCol()
>     valueY = StringCol(10)
>
> class Parent(IsDescription):
>     id = IntCol()
>     valueX = StringCol(50)
>     childList = TableCol(Child)
>
>
> and the usage would be:
>
> h5 = tables.createFile(..., 'parent_tbl',....., Parent,....)
> h5.root.parent_tbl.append(
>     [(1,'valuexxx1', [(1, 'y1'), (2,'y2'), (3,'y3')]),
>      (2,'valuexxx2', [(1, 'yy12'), (2,'yy22')]),
>      (3,'valuexxx3', [(1, 'yyy123')])
>     ])
>
> As you can see the Sub-Array has not a fixed length.

You can only use a Table to keep fixed-length records (mainly due to 
performance purposes), so what you are trying to do is not possible 
with Table objects.

>
> If this is not possible what is the best and fastest way to get such
> a structure accessed?

I'd say that the best way is to use a VLArray with an ObjectAtom, so 
that you can put there different python objects with arbitrary lengths.  
Perhaps this is not the fastest way, but it is quite simple and 
effective.

Cheers,

-- 
Francesc Alted
Freelance developer
Tel +34-964-282-249

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to