#NEWLINE# @ greaterthanorequalcass30 #NEWLINE# @ execute_count ( 5 ) #NEWLINE# def test_named_table_with_mv( self ) : #NEWLINE# #INDENT# '\n        Test NamedTable access to materialized views\n\n        Creates some materialized views using Traditional CQL. Then ensures we can access those materialized view using\n        the NamedKeyspace, and NamedTable interfaces. Tests basic filtering as well.\n\n        @since 3.0.0\n        @jira_ticket PYTHON-406\n        @expected_result Named Tables should have access to materialized views\n\n        @test_category materialized_view\n        ' #NEWLINE# ks = models . DEFAULT_KEYSPACE #NEWLINE# self . session . execute ( 'DROP MATERIALIZED VIEW IF EXISTS {0}.alltimehigh' . format ( ks ) ) #NEWLINE# self . session . execute ( 'DROP MATERIALIZED VIEW IF EXISTS {0}.monthlyhigh' . format ( ks ) ) #NEWLINE# self . session . execute ( 'DROP TABLE IF EXISTS {0}.scores' . format ( ks ) ) #NEWLINE# create_table = 'CREATE TABLE {0}.scores(\n                        user TEXT,\n                        game TEXT,\n                        year INT,\n                        month INT,\n                        day INT,\n                        score INT,\n                        PRIMARY KEY (user, game, year, month, day)\n                        )' . format ( ks ) #NEWLINE# self . session . execute ( create_table ) #NEWLINE# create_mv = 'CREATE MATERIALIZED VIEW {0}.monthlyhigh AS\n                        SELECT game, year, month, score, user, day FROM {0}.scores\n                        WHERE game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND day IS NOT NULL\n                        PRIMARY KEY ((game, year, month), score, user, day)\n                        WITH CLUSTERING ORDER BY (score DESC, user ASC, day ASC)' . format ( ks ) #NEWLINE# self . session . execute ( create_mv ) #NEWLINE# create_mv_alltime = 'CREATE MATERIALIZED VIEW {0}.alltimehigh AS\n                        SELECT * FROM {0}.scores\n                        WHERE game IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL\n                        PRIMARY KEY (game, score, user, year, month, day)\n                        WITH CLUSTERING ORDER BY (score DESC)' . format ( ks ) #NEWLINE# self . session . execute ( create_mv_alltime ) #NEWLINE# prepared_insert = self . session . prepare ( 'INSERT INTO {0}.scores (user, game, year, month, day, score) VALUES  (?, ?, ? ,? ,?, ?)' . format ( ks ) ) #NEWLINE# parameters = { ( 'pcmanus' , 'Coup' , 2015 , 5 , 1 , 4000 ) , ( 'jbellis' , 'Coup' , 2015 , 5 , 3 , 1750 ) , ( 'yukim' , 'Coup' , 2015 , 5 , 3 , 2250 ) , ( 'tjake' , 'Coup' , 2015 , 5 , 3 , 500 ) , ( 'iamaleksey' , 'Coup' , 2015 , 6 , 1 , 2500 ) , ( 'tjake' , 'Coup' , 2015 , 6 , 2 , 1000 ) , ( 'pcmanus' , 'Coup' , 2015 , 6 , 2 , 2000 ) , ( 'jmckenzie' , 'Coup' , 2015 , 6 , 9 , 2700 ) , ( 'jbellis' , 'Coup' , 2015 , 6 , 20 , 3500 ) , ( 'jbellis' , 'Checkers' , 2015 , 6 , 20 , 1200 ) , ( 'jbellis' , 'Chess' , 2015 , 6 , 21 , 3500 ) , ( 'pcmanus' , 'Chess' , 2015 , 1 , 25 , 3200 ) } #NEWLINE# prepared_insert . consistency_level = ConsistencyLevel . ALL #NEWLINE# execute_concurrent_with_args ( self . session , prepared_insert , parameters ) #NEWLINE# key_space = NamedKeyspace ( ks ) #NEWLINE# mv_monthly = key_space . table ( 'monthlyhigh' ) #NEWLINE# mv_all_time = key_space . table ( 'alltimehigh' ) #NEWLINE# self . assertTrue ( self . check_table_size ( 'scores' , filtered_mv_alltime_objects , len ( parameters ) ) ) #NEWLINE# self . assertTrue ( self . check_table_size ( 'monthlyhigh' , key_space , len ( parameters ) ) ) #NEWLINE# self . assertTrue ( self . check_table_size ( 'alltimehigh' , key_space , len ( parameters ) ) ) #NEWLINE# filtered_mv_monthly_objects = mv_monthly . objects . filter ( game = 'Chess' , year = 2015 , month = 6 ) #NEWLINE# self . assertEqual ( len ( filtered_mv_monthly_objects ) , 1 ) #NEWLINE# self . assertEqual ( filtered_mv_monthly_objects [ 0 ] [ 'score' ] , 3500 ) #NEWLINE# self . assertEqual ( filtered_mv_monthly_objects [ 0 ] [ 'user' ] , 'jbellis' ) #NEWLINE# filtered_mv_alltime_objects = mv_all_time . objects . filter ( game = 'Chess' ) #NEWLINE# self . assertEqual ( len ( filtered_mv_alltime_objects ) , 2 ) #NEWLINE# self . assertEqual ( filtered_mv_alltime_objects [ 0 ] [ 'score' ] , 3500 )