Beispiel #1
0
    def setUp(self):
        super(CatalogTestBase, self).setUp()
        gateway = get_gateway()
        self.catalog = Catalog(gateway.jvm.GenericInMemoryCatalog(self.test_catalog_name))

        self.path1 = ObjectPath(self.db1, self.t1)
        self.path2 = ObjectPath(self.db2, self.t2)
        self.path3 = ObjectPath(self.db1, self.t2)
        self.path4 = ObjectPath(self.db1, self.t3)
        self.non_exist_db_path = ObjectPath.from_string("non.exist")
        self.non_exist_object_path = ObjectPath.from_string("db1.nonexist")
Beispiel #2
0
def get_j_obj_to_py_obj_rules():
    """
    Provides rules to transform from Java Objects to Python objects.
    Batch/StreamOperators are not included.
    :return:
    """
    def get_all_subclasses(cls):
        return set(cls.__subclasses__()).union(
            [s for c in cls.__subclasses__() for s in get_all_subclasses(c)])

    from ..vector import VectorIterator

    from pyflink.table.catalog import ObjectPath
    rules = {
        "org.apache.flink.api.java.tuple.Tuple2":
        lambda v: (j_value_to_py_value(v.f0), j_value_to_py_value(v.f1)),
        'com.alibaba.alink.common.linalg.DenseVector$DenseVectorIterator':
        VectorIterator,
        'com.alibaba.alink.common.linalg.SparseVector$SparseVectorVectorIterator':
        VectorIterator,
        'org.apache.flink.table.catalog.ObjectPath':
        lambda v: ObjectPath(j_object_path=v)
    }
    from ..bases.j_obj_wrapper import JavaObjectWrapper
    py_classes = get_all_subclasses(JavaObjectWrapper)
    for py_cls in py_classes:
        if hasattr(py_cls, '_j_cls_name'):
            # noinspection PyProtectedMember
            rules[py_cls._j_cls_name] = py_cls
    return rules
Beispiel #3
0
    def test_create_temporary_table_from_descriptor(self):
        from pyflink.table.schema import Schema

        t_env = self.t_env
        catalog = t_env.get_current_catalog()
        database = t_env.get_current_database()
        schema = Schema.new_builder().column("f0", DataTypes.INT()).build()
        t_env.create_temporary_table(
            "T",
            TableDescriptor.for_connector("fake")
             .schema(schema)
             .option("a", "Test")
             .build())

        self.assertFalse(t_env.get_catalog(catalog).table_exists(ObjectPath(database, "T")))
        gateway = get_gateway()

        catalog_table = CatalogBaseTable(
            t_env._j_tenv.getCatalogManager()
                 .getTable(gateway.jvm.ObjectIdentifier.of(catalog, database, "T"))
                 .get()
                 .getTable())
        self.assertEqual(schema, catalog_table.get_unresolved_schema())
        self.assertEqual("fake", catalog_table.get_options().get("connector"))
        self.assertEqual("Test", catalog_table.get_options().get("a"))
 def get_catalog_object(self):
     tempdir = tempfile.TemporaryDirectory().name
     os.makedirs(tempdir, exist_ok=True)
     url = os.path.join(tempdir, "test_sqlite_db")
     sqlite = SqliteCatalog("sqlite_test_catalog", "test_sqlite_db",
                            "3.19.3", url)
     object_path = ObjectPath("test_sqlite_db", "test_table")
     catalog_object = CatalogObject(sqlite, object_path)
     return sqlite, catalog_object
Beispiel #5
0
    def test_create_table_from_descriptor(self):
        from pyflink.table.schema import Schema

        catalog = self.t_env.get_current_catalog()
        database = self.t_env.get_current_database()
        schema = Schema.new_builder().column("f0", DataTypes.INT()).build()
        self.t_env.create_table(
            "T",
            TableDescriptor.for_connector("fake").schema(schema).option(
                "a", "Test").build())
        object_path = ObjectPath(database, "T")
        self.assertTrue(
            self.t_env.get_catalog(catalog).table_exists(object_path))

        catalog_table = self.t_env.get_catalog(catalog).get_table(object_path)
        self.assertEqual(schema, catalog_table.get_unresolved_schema())
        self.assertEqual("fake", catalog_table.get_options().get("connector"))
        self.assertEqual("Test", catalog_table.get_options().get("a"))