<s> from raco . catalog import Catalog <EOL> import raco . scheme as scheme <EOL> from raco . representation import RepresentationProperties <EOL> from raco . expression import UnnamedAttributeRef as AttIndex <EOL> from raco . catalog import DEFAULT_CARDINALITY <EOL> from . errors import MyriaError <EOL> class MyriaCatalog ( Catalog ) : <EOL> def __init__ ( self , connection ) : <EOL> self . connection = connection <EOL> def get_scheme ( self , rel_key ) : <EOL> relation_args = { <EOL> '<STR_LIT>' : rel_key . user , <EOL> '<STR_LIT>' : rel_key . program , <EOL> '<STR_LIT>' : rel_key . relation <EOL> } <EOL> if not self . connection : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" % rel_key ) <EOL> try : <EOL> dataset_info = self . connection . dataset ( relation_args ) <EOL> except MyriaError : <EOL> raise ValueError ( '<STR_LIT>' . format ( rel_key ) ) <EOL> schema = dataset_info [ '<STR_LIT>' ] <EOL> return scheme . Scheme ( zip ( schema [ '<STR_LIT>' ] , schema [ '<STR_LIT>' ] ) ) <EOL> def get_num_servers ( self ) : <EOL> if not self . connection : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> return len ( self . connection . workers_alive ( ) ) <EOL> def num_tuples ( self , rel_key ) : <EOL> relation_args = { <EOL> '<STR_LIT>' : rel_key . user , <EOL> '<STR_LIT>' : rel_key . program , <EOL> '<STR_LIT>' : rel_key . relation <EOL> } <EOL> if not self . connection : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" % rel_key ) <EOL> try : <EOL> dataset_info = self . connection . dataset ( relation_args ) <EOL> except MyriaError : <EOL> raise ValueError ( rel_key ) <EOL> num_tuples = dataset_info [ '<STR_LIT>' ] <EOL> assert isinstance ( num_tuples , ( int , long ) ) , type ( num_tuples ) <EOL> if num_tuples != - <NUM_LIT:1> : <EOL> assert num_tuples >= <NUM_LIT:0> <EOL> return num_tuples <EOL> return DEFAULT_CARDINALITY <EOL> def partitioning ( self , rel_key ) : <EOL> relation_args = { <EOL> '<STR_LIT>' : rel_key . user , <EOL> '<STR_LIT>' : rel_key . program , <EOL> '<STR_LIT>' : rel_key . relation <EOL> } <EOL> if not self . connection : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" % rel_key ) <EOL> try : <EOL> dataset_info = self . connection . dataset ( relation_args ) <EOL> except MyriaError : <EOL> raise ValueError ( '<STR_LIT>' . format ( rel_key ) ) <EOL> partition_function = dataset_info [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if partition_function and partition_function [ '<STR_LIT:type>' ] in [ <EOL> "<STR_LIT>" , "<STR_LIT>" ] : <EOL> if partition_function [ '<STR_LIT:type>' ] == "<STR_LIT>" : <EOL> indexes = [ partition_function [ '<STR_LIT:index>' ] ] <EOL> else : <EOL> indexes = partition_function [ '<STR_LIT>' ] <EOL> return RepresentationProperties ( <EOL> hash_partitioned = frozenset ( AttIndex ( i ) for i in indexes ) ) <EOL> return RepresentationProperties ( ) </s>
