Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _create_udf():
inputs = [('field1', 'string'), ('field2', 'integer')]
outputs = [('output1', 'integer'), ('output2', 'string')]
impl = 'function(r,emit) { emit({output1: r.field2, output2: r.field1 }); }'
udf = datalab.bigquery.UDF(inputs, outputs, 'foo', impl)
return udf
def test_sql_building(self):
context = self._create_context()
table = datalab.bigquery.Table('test:requestlogs.today', context=context)
udf = self._create_udf()
query = datalab.bigquery.Query('SELECT * FROM foo($t)', t=table, udfs=[udf], context=context)
expected_js = '\nfoo=function(r,emit) { emit({output1: r.field2, output2: r.field1 }); };\n' +\
'bigquery.defineFunction(\'foo\', ["field1", "field2"], ' +\
'[{"name": "output1", "type": "integer"}, ' +\
'{"name": "output2", "type": "string"}], foo);'
self.assertEqual(query.sql, 'SELECT * FROM '
'(SELECT output1, output2 FROM foo([test:requestlogs.today]))')
self.assertEqual(udf._code, expected_js)
def test_create_python_module(self):
datalab.utils.commands._modules._create_python_module('bar', 'y=1')
self.assertIsNotNone(sys.modules['bar'])
self.assertEqual(1, sys.modules['bar'].y)
def _create_context():
project_id = 'test'
creds = mock.Mock(spec=google.auth.credentials.Credentials)
return datalab.context.Context(project_id, creds)
def _create_context():
project_id = 'test'
creds = mock.Mock(spec=google.auth.credentials.Credentials)
return datalab.context.Context(project_id, creds)
def _create_context():
project_id = 'test'
creds = mock.Mock(spec=google.auth.credentials.Credentials)
return datalab.context.Context(project_id, creds)
def _create_context():
project_id = 'test'
creds = mock.Mock(spec=google.auth.credentials.Credentials)
return datalab.context.Context(project_id, creds)
def _create_context():
project_id = 'test'
creds = mock.Mock(spec=google.auth.credentials.Credentials)
return datalab.context.Context(project_id, creds)
def _create_context():
project_id = 'test'
creds = mock.Mock(spec=google.auth.credentials.Credentials)
return datalab.context.Context(project_id, creds)
def _create_context():
project_id = 'test'
creds = mock.Mock(spec=google.auth.credentials.Credentials)
return datalab.context.Context(project_id, creds)