예제 #1
0
 def test_typing_payload_builder(self):
     result = self.get_payload_from_typing_hints(self.values)
     decoded = RowCoder(result.schema).decode(result.payload)
     for key, value in self.values.items():
         self.assertEqual(getattr(decoded, key), value)
 def build(self):
     row = self._get_named_tuple_instance()
     schema = named_tuple_to_schema(type(row))
     return ExternalConfigurationPayload(
         schema=schema, payload=RowCoder(schema).encode(row))
예제 #3
0
    def test_none_in_non_nullable_field_throws(self):
        Test = typing.NamedTuple('Test', [('foo', unicode)])

        c = RowCoder.from_type_hint(Test, None)
        self.assertRaises(ValueError, lambda: c.encode(Test(foo=None)))
예제 #4
0
def parse_string_payload(input_byte):
    payload = ExternalConfigurationPayload()
    payload.ParseFromString(input_byte)

    return RowCoder(payload.schema).decode(payload.payload)._asdict()
예제 #5
0
파일: jdbc.py 프로젝트: nielm/beam
  def __init__(
      self,
      table_name,
      driver_class_name,
      jdbc_url,
      username,
      password,
      query=None,
      output_parallelization=None,
      fetch_size=None,
      connection_properties=None,
      connection_init_sqls=None,
      expansion_service=None,
      classpath=None,
  ):
    """
    Initializes a read operation from Jdbc.

    :param driver_class_name: name of the jdbc driver class
    :param jdbc_url: full jdbc url to the database.
    :param username: database username
    :param password: database password
    :param query: sql query to be executed
    :param output_parallelization: is output parallelization on
    :param fetch_size: how many rows to fetch
    :param connection_properties: properties of the jdbc connection
                                  passed as string with format
                                  [propertyName=property;]*
    :param connection_init_sqls: required only for MySql and MariaDB.
                                 passed as list of strings
    :param expansion_service: The address (host:port) of the ExpansionService.
    :param classpath: A list of JARs or Java packages to include in the
                      classpath for the expansion service. This option is
                      usually needed for `jdbc` to include extra JDBC driver
                      packages.
                      The packages can be in these three formats: (1) A local
                      file, (2) A URL, (3) A gradle-style identifier of a Maven
                      package (e.g. "org.postgresql:postgresql:42.3.1").
                      By default, this argument includes a Postgres SQL JDBC
                      driver.
    """
    classpath = classpath or DEFAULT_JDBC_CLASSPATH
    super().__init__(
        self.URN,
        NamedTupleBasedPayloadBuilder(
            JdbcConfigSchema(
                location=table_name,
                config=RowCoder(
                    typing_to_runner_api(Config).row_type.schema).encode(
                        Config(
                            driver_class_name=driver_class_name,
                            jdbc_url=jdbc_url,
                            username=username,
                            password=password,
                            connection_properties=connection_properties,
                            connection_init_sqls=connection_init_sqls,
                            write_statement=None,
                            read_query=query,
                            fetch_size=fetch_size,
                            output_parallelization=output_parallelization,
                            autosharding=None,
                        ))),
        ),
        expansion_service or default_io_expansion_service(classpath),
    )