How to use datalab - 10 common examples

To help you get started, we’ve selected a few datalab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googledatalab / pydatalab / legacy_tests / bigquery / udf_tests.py View on Github external
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
github googledatalab / pydatalab / legacy_tests / bigquery / udf_tests.py View on Github external
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)
github googledatalab / pydatalab / legacy_tests / kernel / module_tests.py View on Github external
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)
github googledatalab / pydatalab / legacy_tests / bigquery / dataset_tests.py View on Github external
def _create_context():
    project_id = 'test'
    creds = mock.Mock(spec=google.auth.credentials.Credentials)
    return datalab.context.Context(project_id, creds)
github googledatalab / pydatalab / legacy_tests / bigquery / query_tests.py View on Github external
def _create_context():
    project_id = 'test'
    creds = mock.Mock(spec=google.auth.credentials.Credentials)
    return datalab.context.Context(project_id, creds)
github googledatalab / pydatalab / legacy_tests / bigquery / udf_tests.py View on Github external
def _create_context():
    project_id = 'test'
    creds = mock.Mock(spec=google.auth.credentials.Credentials)
    return datalab.context.Context(project_id, creds)
github googledatalab / pydatalab / legacy_tests / storage / bucket_tests.py View on Github external
def _create_context():
    project_id = 'test'
    creds = mock.Mock(spec=google.auth.credentials.Credentials)
    return datalab.context.Context(project_id, creds)
github googledatalab / pydatalab / legacy_tests / bigquery / view_tests.py View on Github external
def _create_context():
    project_id = 'test'
    creds = mock.Mock(spec=google.auth.credentials.Credentials)
    return datalab.context.Context(project_id, creds)
github googledatalab / pydatalab / legacy_tests / kernel / bigquery_tests.py View on Github external
def _create_context():
    project_id = 'test'
    creds = mock.Mock(spec=google.auth.credentials.Credentials)
    return datalab.context.Context(project_id, creds)
github googledatalab / pydatalab / legacy_tests / bigquery / jobs_tests.py View on Github external
def _create_context():
    project_id = 'test'
    creds = mock.Mock(spec=google.auth.credentials.Credentials)
    return datalab.context.Context(project_id, creds)