'Test NamedTable access to materialized views
Creates some materialized views using Traditional CQL. Then ensures we can access those materialized view using
the NamedKeyspace, and NamedTable interfaces. Tests basic filtering as well.
@since 3.0.0
@jira_ticket PYTHON-406
@expected_result Named Tables should have access to materialized views
@test_category materialized_view'

@greaterthanorequalcass30
@execute_count(5)
def test_named_table_with_mv(self):

    ks = models.DEFAULT_KEYSPACE
    self.session.execute('DROP    MATERIALIZED    VIEW    IF    EXISTS    {0}.alltimehigh'.format(ks))
    self.session.execute('DROP    MATERIALIZED    VIEW    IF    EXISTS    {0}.monthlyhigh'.format(ks))
    self.session.execute('DROP    TABLE    IF    EXISTS    {0}.scores'.format(ks))
    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)
    self.session.execute(create_table)
    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)
    self.session.execute(create_mv)
    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)
    self.session.execute(create_mv_alltime)
    prepared_insert = self.session.prepare('INSERT    INTO    {0}.scores    (user,    game,    year,    month,    day,    score)    VALUES        (?,    ?,    ?    ,?    ,?,    ?)'.format(ks))
    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))
    prepared_insert.consistency_level = ConsistencyLevel.ALL
    execute_concurrent_with_args(self.session, prepared_insert, parameters)
    key_space = NamedKeyspace(ks)
    mv_monthly = key_space.table('monthlyhigh')
    mv_all_time = key_space.table('alltimehigh')
    self.assertTrue(self.check_table_size('scores', key_space, len(parameters)))
    self.assertTrue(self.check_table_size('monthlyhigh', key_space, len(parameters)))
    self.assertTrue(self.check_table_size('alltimehigh', key_space, len(parameters)))
    filtered_mv_monthly_objects = mv_monthly.objects.filter(game='Chess', year=2015, month=6)
    self.assertEqual(len(filtered_mv_monthly_objects), 1)
    self.assertEqual(filtered_mv_monthly_objects[0]['score'], 3500)
    self.assertEqual(filtered_mv_monthly_objects[0]['user'], 'jbellis')
    filtered_mv_alltime_objects = mv_all_time.objects.filter(game='Chess')
    self.assertEqual(len(filtered_mv_alltime_objects), 2)
    self.assertEqual(filtered_mv_alltime_objects[0]['score'], 3500)
