Ejemplo n.º 1
0
    def setUp(self):
        # Set options
        self.options = {
            'fdw_key': '/opt/key/key.json',
            'fdw_dataset': 'bigquery-public-data.usa_names',
            'fdw_table': 'usa_1910_current',
            'fdw_verbose': 'true',
            'fdw_sql_dialect': 'standard',
            'fdw_group': 'false',
            'fdw_casting': 'false',
        }

        # Set column list (ordered dict of ColumnDefinition from Multicorn)
        self.columns = OrderedDict([
            ('state',
             multicorn.ColumnDefinition(column_name='state',
                                        type_oid=25,
                                        base_type_name='text')),
            ('gender',
             multicorn.ColumnDefinition(column_name='gender',
                                        type_oid=25,
                                        base_type_name='text')),
            ('year',
             multicorn.ColumnDefinition(column_name='year',
                                        type_oid=20,
                                        base_type_name='bigint')),
            ('name',
             multicorn.ColumnDefinition(column_name='name',
                                        type_oid=25,
                                        base_type_name='text')),
            ('number',
             multicorn.ColumnDefinition(column_name='number',
                                        type_oid=20,
                                        base_type_name='bigint'))
        ])

        # Define Quals as defined by Multicorn
        self.quals = [
            multicorn.Qual(field_name='number', operator='>', value=1000),
            multicorn.Qual(field_name='year', operator='=', value=2017),
        ]

        # Set instance of ConstantForeignDataWrapper
        self.fdw = ConstantForeignDataWrapper(self.options, self.columns)
Ejemplo n.º 2
0
    def runCheck(self, fdw):
        self.assertEquals(5, self.count(fdw, {}))

        self.assertEquals(1, self.count(fdw, [multicorn.Qual("a", "=", 5)]))
        self.assertEquals(1, self.count(fdw, [multicorn.Qual("a", "=", 8)]))

        self.assertEquals(2, self.count(fdw, [multicorn.Qual("a", ">", 7)]))
        self.assertEquals(3, self.count(fdw, [multicorn.Qual("a", ">=", 7)]))
        self.assertEquals(2, self.count(fdw, [multicorn.Qual("a", "<", 7)]))
        self.assertEquals(3, self.count(fdw, [multicorn.Qual("a", "<=", 7)]))

        for one in fdw.execute([multicorn.Qual("a", "=", 5)],
                               self.column_list()):
            self.assertEquals(one, {"a": 5, "b": 3})

        for one in fdw.execute([multicorn.Qual("a", "=", 5)], ["a"]):
            self.assertEquals(one, {"a": 5})
Ejemplo n.º 3
0
    def test_buildWhereClause_2(self):
        # Test with partition pseudo column
        q = self.quals
        q.append(
            multicorn.Qual(field_name='partition_date',
                           operator='=',
                           value=datetime.datetime(2018, 5, 27, 19, 53,
                                                   42).date()))

        self.fdw.bq = self.fdw.getClient()
        clause, parameters = self.fdw.buildWhereClause(q)

        self.assertIsInstance(clause, str)
        self.assertIsInstance(parameters, list)
        for parameter in parameters:
            self.assertIsInstance(parameter,
                                  bigquery.query.ScalarQueryParameter)
Ejemplo n.º 4
0
 def makeQual(self, op, left, right):
     return multicorn.Qual(op, left, right)