Ejemplo n.º 1
0
    def test_create_phoenix_table(self):
        table_data = {
            "data_file":
            "./tables/us_population.csv",
            "create_sql":
            """CREATE TABLE IF NOT EXISTS us_population (\n  state CHAR(2) NOT NULL,\n  city VARCHAR NOT NULL,\n  """
            """population BIGINT\n  CONSTRAINT my_pk PRIMARY KEY (state, city)\n)\n""",
            "insert_sql":
            "UPSERT INTO us_population VALUES %(values)s",
            "table_name":
            "us_population",
            "dialects": ["phoenix"],
            "transactional":
            True,
            "is_multi_inserts":
            True
        }

        with patch(
                'beeswax.management.commands.beeswax_install_examples.make_notebook'
        ) as make_notebook:
            SampleTable(table_data, 'phoenix', 'default').install(self.user)

            make_notebook.assert_called_with(
                name='Insert data in sample table us_population',
                editor_type='phoenix',
                statement=
                "UPSERT INTO us_population VALUES ('CA', 'San Jose', 912332)",
                status='ready',
                database='default',
                on_success_url='assist.db.refresh',
                is_task=False)
Ejemplo n.º 2
0
  def test_create_table_load_data_but_no_fs(self):
    table_data =   {
      "data_file": "sample_07.csv",
      "create_sql": "CREATE TABLE `sample_07` (\n  `code` string ,\n  `description` string ,\n  `total_emp` int ,\n  `salary` int )\nSTORED AS parquet\nTBLPROPERTIES ('transactional'='true', 'transactional_properties'='insert_only')\n",
      "table_name": "sample_07",
    }

    with patch('beeswax.management.commands.beeswax_install_examples.make_notebook') as make_notebook:
      with patch('beeswax.management.commands.beeswax_install_examples.has_concurrency_support') as has_concurrency_support:
        has_concurrency_support.return_value = True

        SampleTable(table_data, 'hive', 'default').install(self.user)

        make_notebook.assert_not_called()
Ejemplo n.º 3
0
  def test_load_web_logs_with_concurrency_support(self):
    table_data = {
      "partition_files": {
        "`date`='2015-11-18'": "web_logs_1.csv",
        "`date`='2015-11-19'": "web_logs_2.csv",
        "`date`='2015-11-20'": "web_logs_3.csv",
        "`date`='2015-11-21'": "web_logs_4.csv"
      },
      "create_sql":
          """CREATE TABLE `web_logs`  (  `_version_` bigint,   `app` string,   `bytes` int,   `city` string,   `client_ip` string,   """
          """`code` smallint,   `country_code` string,   `country_code3` string,   `country_name` string,   `device_family` string,  """
          """ `extension` string,   `latitude` float,   `longitude` float,   `method` string,   `os_family` string,   `os_major` string,"""
          """   `protocol` string,   `record` string,   `referer` string,   `region_code` string,   `request` string,   `subapp` string,"""
          """   `time` string,   `url` string,   `user_agent` string,   `user_agent_family` string,   `user_agent_major` string,"""
          """   `id` string)\nPARTITIONED BY (  `date` string  )\nSTORED AS parquet\nTBLPROPERTIES ('transactional'='true',"""
          """ 'transactional_properties'='insert_only')""",
      "table_name": "web_logs",
      "columns": [
          {"name": "_version_", "type": "bigint"}, {"name": "app", "type": "string"}, {"name": "bytes", "type": "int"},
          {"name": "city", "type": "string"}, {"name": "client_ip", "type": "string"}, {"name": "code", "type": "smallint"},
          {"name": "country_code", "type": "string"}, {"name": "country_code3", "type": "string"},
          {"name": "country_name", "type": "string"}, {"name": "device_family", "type": "string"},
          {"name": "extension", "type": "string"}, {"name": "latitude", "type": "float"},
          {"name": "longitude", "type": "float"}, {"name": "method", "type": "string"},
          {"name": "os_family", "type": "string"}, {"name": "os_major", "type": "string"},
          {"name": "protocol", "type": "string"}, {"name": "record", "type": "string"},
          {"name": "referer", "type": "string"}, {"name": "region_code", "type": "string"},
          {"name": "request", "type": "string"}, {"name": "subapp", "type": "string"},
          {"name": "time", "type": "string"}, {"name": "url", "type": "string"},
          {"name": "user_agent", "type": "string"}, {"name": "user_agent_family", "type": "string"},
          {"name": "user_agent_major", "type": "string"}, {"name": "id", "type": "string"}, {"name": "date", "type": "string"}],
      "transactional": True
    }

    with patch('beeswax.management.commands.beeswax_install_examples.make_notebook') as make_notebook:
      with patch('beeswax.management.commands.beeswax_install_examples.has_concurrency_support') as has_concurrency_support:
        has_concurrency_support.return_value = True

        SampleTable(table_data, 'hive', 'default').install(self.user)

        make_notebook.assert_called()