Ejemplo n.º 1
0
    def test_query(self):
        conn = MaxComputeConnection(testing.get_datasource())
        rs = conn.query("select * from notexist limit 1")
        self.assertFalse(rs.success())
        self.assertTrue("Table not found" in rs.error())

        rs = conn.query(
            "select * from alifin_jtest_dev.sqlflow_iris_train limit 1")
        self.assertTrue(rs.success())
        rows = [r for r in rs]
        self.assertEqual(1, len(rows))

        rs = conn.query(
            "select * from alifin_jtest_dev.sqlflow_iris_train limit 20")
        self.assertTrue(rs.success())

        col_info = rs.column_info()
        self.assertEqual([('sepal_length', 'double'),
                          ('sepal_width', 'double'),
                          ('petal_length', 'double'),
                          ('petal_width', 'double'), ('class', 'bigint')],
                         col_info)

        rows = [r for r in rs]
        self.assertTrue(20, len(rows))
Ejemplo n.º 2
0
 def test_get_table_schema(self):
     conn = MaxComputeConnection(testing.get_datasource())
     col_info = conn.get_table_schema("sqlflow_iris_train")
     self.assertEqual([('sepal_length', 'DOUBLE'),
                       ('sepal_width', 'DOUBLE'),
                       ('petal_length', 'DOUBLE'),
                       ('petal_width', 'DOUBLE'), ('class', 'BIGINT')],
                      col_info)
Ejemplo n.º 3
0
def get_oss_model_save_path(datasource, model_name, user=""):
    if not model_name:
        return None
    _, _, _, project = MaxComputeConnection.get_uri_parts(datasource)
    if user == "":
        user = "******"
    return "/".join([project, user, model_name])
Ejemplo n.º 4
0
def get_project(datasource):
    """Get the project info from given datasource

    Args:
        datasource: The odps url to extract project
    """
    _, _, _, project = MaxComputeConnection.get_uri_parts(datasource)
    return project
Ejemplo n.º 5
0
    def test_query(self):
        conn = MaxComputeConnection(testing.get_datasource())
        try:
            conn.query("select * from notexist limit 1")
            self.assertTrue(False)
        except Exception as e:
            self.assertTrue("Table not found" in str(e))

        rs = conn.query(
            "select * from alifin_jtest_dev.sqlflow_iris_train limit 1")
        self.assertTrue(rs.success())
        rows = [r for r in rs]
        self.assertEqual(1, len(rows))

        rs = conn.query(
            "select * from alifin_jtest_dev.sqlflow_iris_train limit 20")
        self.assertTrue(rs.success())

        col_info = rs.column_info()
        self.assertEqual([('sepal_length', 'DOUBLE'),
                          ('sepal_width', 'DOUBLE'),
                          ('petal_length', 'DOUBLE'),
                          ('petal_width', 'DOUBLE'), ('class', 'BIGINT')],
                         col_info)

        rows = [r for r in rs]
        self.assertTrue(20, len(rows))
Ejemplo n.º 6
0
def drop_pai_model(datasource, model_name):
    """Drop PAI model

    Args:
        datasource: current datasource
        model_name: name of the model to drop
    """
    user, passwd, address, database = MaxComputeConnection.get_uri_parts(
        datasource)
    cmd = "drop offlinemodel if exists %s" % model_name
    subprocess.run([
        "odpscmd", "-u", user, "-p", passwd, "--project", database,
        "--endpoint", address, "-e", cmd
    ],
                   check=True)
Ejemplo n.º 7
0
def submit_pai_task(pai_cmd, datasource):
    """Submit given cmd to PAI which manipulate datasource

    Args:
        pai_cmd: The command to submit
        datasource: The datasource this cmd will manipulate
    """
    user, passwd, address, project = MaxComputeConnection.get_uri_parts(
        datasource)
    cmd = [
        "odpscmd", "--instance-priority", "9", "-u", user, "-p", passwd,
        "--project", project, "--endpoint", address, "-e", pai_cmd
    ]
    exitcode = run_command_and_log(cmd)
    if exitcode != 0:
        raise SQLFlowDiagnostic("Execute odps cmd fail: cmd is %s" %
                                " ".join(cmd))
Ejemplo n.º 8
0
 def test_exec(self):
     conn = MaxComputeConnection(testing.get_datasource())
     rs = conn.exec(
         "create table alifin_jtest_dev.sqlflow_test_exec(a int)")
     self.assertTrue(rs)
     rs = conn.exec(
         "insert into alifin_jtest_dev.sqlflow_test_exec values(1), (2)")
     self.assertTrue(rs)
     rs = conn.query("select * from alifin_jtest_dev.sqlflow_test_exec")
     self.assertTrue(rs.success())
     rows = [r for r in rs]
     self.assertTrue(2, len(rows))
     rs = conn.exec("drop table alifin_jtest_dev.sqlflow_test_exec")
     self.assertTrue(rs)
Ejemplo n.º 9
0
def parse_maxcompute_dsn(datasource):
    return MaxComputeConnection.get_uri_parts(datasource)
Ejemplo n.º 10
0
 def test_connecion(self):
     try:
         conn = MaxComputeConnection(testing.get_datasource())
         conn.close()
     except:  # noqa: E722
         self.fail()