Exemple #1
0
    def connect(self, connector_descriptor):
        """
        Creates a table source and/or table sink from a descriptor.

        Descriptors allow for declaring the communication to external systems in an
        implementation-agnostic way. The classpath is scanned for suitable table factories that
        match the desired configuration.

        The following example shows how to read from a connector using a JSON format and
        registering a table source as "MyTable":
        ::

            >>> table_env\\
            ...     .connect(ExternalSystemXYZ()
            ...              .version("0.11"))\\
            ...     .with_format(Json()
            ...                 .json_schema("{...}")
            ...                 .fail_on_missing_field(False))\\
            ...     .with_schema(Schema()
            ...                 .field("user-name", "VARCHAR")
            ...                 .from_origin_field("u_name")
            ...                 .field("count", "DECIMAL"))\\
            ...     .register_table_source("MyTable")

        :param connector_descriptor: Connector descriptor describing the external system.
        :return: A :class:`BatchTableDescriptor` used to build the table source/sink.
        """
        # type: (ConnectorDescriptor) -> BatchTableDescriptor
        return BatchTableDescriptor(
            self._j_tenv.connect(connector_descriptor._j_connector_descriptor))
Exemple #2
0
    def connect(self, connector_descriptor):
        """
        Creates a table source and/or table sink from a descriptor.

        Descriptors allow for declaring the communication to external systems in an
        implementation-agnostic way. The classpath is scanned for suitable table factories that
        match the desired configuration.

        The following example shows how to read from a connector using a JSON format and
        registering a table source as "MyTable":
        ::

            >>> table_env \\
            ...     .connect(ExternalSystemXYZ()
            ...              .version("0.11")) \\
            ...     .with_format(Json()
            ...                  .json_schema("{...}")
            ...                  .fail_on_missing_field(False)) \\
            ...     .with_schema(Schema()
            ...                  .field("user-name", "VARCHAR")
            ...                  .from_origin_field("u_name")
            ...                  .field("count", "DECIMAL")) \\
            ...     .register_table_source("MyTable")

        :param connector_descriptor: Connector descriptor describing the external system.
        :type connector_descriptor: ConnectorDescriptor
        :return: A :class:`BatchTableDescriptor` or a :class:`StreamTableDescriptor`
                 (for blink planner) used to build the table source/sink.
        :rtype: BatchTableDescriptor or StreamTableDescriptor
        """
        gateway = get_gateway()
        blink_t_env_class = get_java_class(gateway.jvm.org.apache.flink.table.
                                           api.internal.TableEnvironmentImpl)
        if blink_t_env_class == self._j_tenv.getClass():
            return StreamTableDescriptor(
                self._j_tenv.connect(
                    connector_descriptor._j_connector_descriptor))
        else:
            return BatchTableDescriptor(
                self._j_tenv.connect(
                    connector_descriptor._j_connector_descriptor))