def test_select(): dataset = mock_data_set() qb = QueryBuilder(dataset) eq_(qb.column_exps, '*') qb_w_select = qb.select('x,y') assert_is_not(qb, qb_w_select) eq_(qb_w_select.column_exps, 'x,y') qb_w_select_and_from = qb_w_select.frm('bogus') q = qb_w_select_and_from.query assert_is_instance(q, Query) assert_sequence_equal(q.schema.fields, [ Field(name="x", type="INTEGER", schema_name="bogus"), Field(name="y", type="INTEGER", schema_name="bogus") ]) compare(q.operations, ProjectionOp(LoadOp('bogus'), Var('x'), Var('y'))) qb_select_y_from_bogus = qb.select('y').frm('bogus') eq_(qb_select_y_from_bogus.column_exps, 'y') assert_sequence_equal( qb_select_y_from_bogus.query.schema.fields, [Field(name="y", type="INTEGER", schema_name="bogus")]) compare(qb_select_y_from_bogus.query.operations, ProjectionOp(LoadOp('bogus'), Var('y')))
def test_select(): dataset = mock_data_set() qb = QueryBuilder(dataset) eq_(qb.column_exps, '*') qb_w_select = qb.select('x,y') assert_is_not(qb, qb_w_select) eq_(qb_w_select.column_exps, 'x,y') qb_w_select_and_from = qb_w_select.frm('bogus') q = qb_w_select_and_from.query assert_is_instance(q, Query) assert_sequence_equal( q.schema.fields, [ Field(name="x", type="INTEGER", schema_name="bogus"), Field(name="y", type="INTEGER", schema_name="bogus") ] ) compare( q.operations, ProjectionOp(LoadOp('bogus'), Var('x'), Var('y')) ) qb_select_y_from_bogus = qb.select('y').frm('bogus') eq_(qb_select_y_from_bogus.column_exps, 'y') assert_sequence_equal( qb_select_y_from_bogus.query.schema.fields, [ Field(name="y", type="INTEGER", schema_name="bogus") ] ) compare( qb_select_y_from_bogus.query.operations, ProjectionOp(LoadOp('bogus'),Var('y')) )