def test_01(self): obj = self.schema.alloc() obj[:] = [1] obj.index_add() query = Sos.Query(self.db) attr_name = 'int16' query.select([attr_name], from_=['query_test2'], where=[(attr_name, Sos.COND_GE, 1), (attr_name, Sos.COND_LE, 2)], order_by=attr_name) query.begin()
def setUpClass(cls): cls.setUpDb('query_test_cont') cls.schema1 = Sos.Schema() cls.schema1.from_template( 'query_test', [{ "name": "int16", "type": "int16", "index": {} }, { "name": "int32", "type": "int32", "index": {} }, { "name": "int64", "type": "int64", "index": {} }, { "name": "uint16", "type": "uint16", "index": {} }, { "name": "uint32", "type": "uint32", "index": {} }, { "name": "uint64", "type": "uint64", "index": {} }, { "name": "float", "type": "float", "index": {} }, { "name": "double", "type": "double", "index": {} }, { "name": "timestamp", "type": "timestamp", "index": {} }, { "name": "string", "type": "char_array", "index": {} }, { "name": "byte_array", "type": "byte_array", "index": {} }, { "name": "int16_array", "type": "int16_array", "index": {} }, { "name": "int32_array", "type": "int32_array", "index": {} }, { "name": "int64_array", "type": "int64_array", "index": {} }, { "name": "uint16_array", "type": "uint16_array", "index": {} }, { "name": "uint32_array", "type": "uint32_array", "index": {} }, { "name": "uint64_array", "type": "uint64_array", "index": {} }, { "name": "float_array", "type": "float_array", "index": {} }, { "name": "double_array", "type": "double_array", "index": {} }, { "name": "int32_no_idx", "type": "int32" }, { "name": "int16_int32_", "type": "join", "join_attrs": ["int16", "int32"], "index": {} }, { "name": "int16_int32_int64", "type": "join", "join_attrs": ["int16", "int32", "int64"], "index": {} }]) cls.schema1.add(cls.db) cls.schema2 = Sos.Schema() cls.schema2.from_template('query_test_2', [ { "name": "int32_2", "type": "int32", "index": {} }, { "name": "timestamp", "type": "timestamp", "index": {} }, ]) cls.schema2.add(cls.db) cls.query = Sos.Query(cls.db)
def select(self, columns, where=None, order_by=None, desc=False, from_=None, unique=False): """Specify which columns, order, and record selection criteria Positional Parameters: -- A list of column-specifications. A column-specification can be a ColSpec, or a string. In either case, the column-name is a interpretted as schema-name '.' attr-name. The schema-name portion will be used to discriminate between schema present in the container. The column-name schema-name '.*' and '*' are wildcards to select all columns in a schema and all columns in the from_ keyword parameter respectively. Keyword Arguments: from_ -- An array of schema name being queried (default is all) where -- An array of query conditions order_by -- The name of the attribute by which to order results If the order_by keyword is not specified, the first column in the column-specification is presumed to be the key. If this column is not indexed, an exception will be thrown. desc -- If set to True, the results will be returned in 'reverse' order. The defalt is False unique -- Return only a single result for each matching the where condition Examples: ds = SosDataSource() ds.config(path = '/DATA15/orion/ldms_data') ds.select([ 'meminfo[timestamp]', 'meminfo[job_id]', 'meminfo[component_id]', 'meminfo[MemFree]', 'meminfo[MemAvailable]', 'vmstat[nr_free_pages]' ], where = [ ('job_id', Sos.COND_GT, 1), ( 'timestamp', Sos.COND_GE, ( 15451234, 0 )) ], order_by = 'job_comp_time' ) """ self.query_ = Sos.Query(self.cont) self.query_.select(columns, where=where, from_=from_, order_by=order_by, desc=desc, unique=unique) col_no = 0 self.colnames = [] for col in self.query_.get_columns(): self.colnames.append(col.attr_name) col_no += 1