Exemplo n.º 1
0
def _create_table(table_name, datasets, columns, descriptor):
    builder = descriptor_builder(table_name, descriptor)
    schemas = [DatasetSchema.from_dataset(ds, columns) for ds in datasets]
    table_desc, dminfo = builder.execute(schemas)

    root, table, subtable = table_path_split(table_name)
    table_path = root / table

    from daskms.descriptors.ms import MSDescriptorBuilder
    from daskms.descriptors.ms_subtable import MSSubTableDescriptorBuilder

    if not subtable and isinstance(builder, MSDescriptorBuilder):
        table_path = str(table_path)

        # Create the MS
        with pt.default_ms(table_path, tabdesc=table_desc, dminfo=dminfo):
            pass

        return _writable_table_proxy(table_path)
    elif subtable:
        # NOTE(sjperkins)
        # Recreate the subtable path with OS separator components
        # This avoids accessing the subtable via the main table
        # (e.g. WSRT.MS::SOURCE)
        # which can cause lock issues as the subtables seemingly
        # inherit the parent table lock
        subtable_path = str(table_path / subtable)

        # Create the subtable
        if isinstance(builder, MSSubTableDescriptorBuilder):
            with pt.default_ms_subtable(subtable,
                                        subtable_path,
                                        tabdesc=table_desc,
                                        dminfo=dminfo):
                pass
        else:
            with pt.table(subtable_path, table_desc, dminfo=dminfo, ack=False):
                pass

        # Add subtable to the main table
        table_proxy = _writable_table_proxy(str(table_path))
        table_proxy.putkeywords({subtable: "Table: " + subtable_path}).result()
        del table_proxy

        # Return TableProxy
        return _writable_table_proxy(subtable_path)
    else:
        # Create the table
        with pt.table(str(table_path), table_desc, dminfo=dminfo, ack=False):
            pass

        return _writable_table_proxy(str(table_path))
Exemplo n.º 2
0
 def create_ms(filename, table_desc=None, dm_info=None):
     with tables.default_ms(filename, table_desc, dm_info) as T:
         # Add the SOURCE subtable
         source_filename = os.path.join(os.getcwd(), filename, "SOURCE")
         tables.default_ms_subtable("SOURCE", source_filename)
         T.putkeyword("SOURCE", "Table: %s" % source_filename)