def test_avro_spec(self):
    '\n        Check an Avro Kafka subscription creates the right table.\n        '
    schema = '\n            { "type" : "record",\n              "namespace" : "io.deephaven.examples",\n              "name" : "share_price",\n              "fields" : [\n                { "name" : "Symbol", "type" : "string" },\n                { "name" : "Side",   "type" : "string" },\n                { "name" : "Qty",    "type" : "int"    },\n                { "name" : "Price",  "type" : "double" }\n              ]\n            }\n            '
    schema_str = ('{ "schema" : "%s" }' % schema.replace('\n', ' ').replace('"', '\\"'))
    sys_str = ("\n            curl -X POST                 -H 'Content-type: application/vnd.schemaregistry.v1+json; artifactType=AVRO'                 --data-binary '%s'                 http://redpanda:8081/subjects/share_price_record/versions\n            " % schema_str)
    r = os.system(sys_str)
    self.assertEqual(0, r)
    with self.subTest(msg='straight schema, no mapping'):
        t = ck.consume({'bootstrap.servers': 'redpanda:29092', 'schema.registry.url': 'http://redpanda:8081'}, 'share_price', key_spec=KeyValueSpec.IGNORE, value_spec=ck.avro_spec('share_price_record', schema_version='1'), table_type=TableType.append())
        cols = t.columns
        self.assertEqual(7, len(cols))
        self._assert_common_cols(cols)
        self.assertEqual('Symbol', cols[3].name)
        self.assertEqual(dtypes.string, cols[3].data_type)
        self.assertEqual('Side', cols[4].name)
        self.assertEqual(dtypes.string, cols[4].data_type)
        self.assertEqual('Qty', cols[5].name)
        self.assertEqual(dtypes.int32, cols[5].data_type)
        self.assertEqual('Price', cols[6].name)
        self.assertEqual(dtypes.double, cols[6].data_type)
    with self.subTest(msg='mapping_only (filter out some schema fields)'):
        m = {'Symbol': 'Ticker', 'Price': 'Dollars'}
        t = ck.consume({'bootstrap.servers': 'redpanda:29092', 'schema.registry.url': 'http://redpanda:8081'}, 'share_price', key_spec=KeyValueSpec.IGNORE, value_spec=ck.avro_spec('share_price_record', mapping=m, mapped_only=True), table_type=TableType.append())
        cols = t.columns
        self.assertEqual(5, len(cols))
        self._assert_common_cols(cols)
        self.assertEqual('Ticker', cols[3].name)
        self.assertEqual(dtypes.string, cols[3].data_type)
        self.assertEqual('Dollars', cols[4].name)
        self.assertEqual(dtypes.double, cols[4].data_type)
    with self.subTest(msg='mapping (rename some fields)'):
        m = {'Symbol': 'Ticker', 'Qty': 'Quantity'}
        t = ck.consume({'bootstrap.servers': 'redpanda:29092', 'schema.registry.url': 'http://redpanda:8081'}, 'share_price', key_spec=KeyValueSpec.IGNORE, value_spec=ck.avro_spec('share_price_record', mapping=m), table_type=TableType.append())
        cols = t.columns
        self.assertEqual(7, len(cols))
        self._assert_common_cols(cols)
        self.assertEqual('Ticker', cols[3].name)
        self.assertEqual(dtypes.string, cols[3].data_type)
        self.assertEqual('Side', cols[4].name)
        self.assertEqual(dtypes.string, cols[4].data_type)
        self.assertEqual('Quantity', cols[5].name)
        self.assertEqual(dtypes.int32, cols[5].data_type)
        self.assertEqual('Price', cols[6].name)
        self.assertEqual(dtypes.double, cols[6].data_type)
Check an Avro Kafka subscription creates the right table.
def test_avro_spec(self):
    '\n        \n        '
    schema = '\n            { "type" : "record",\n              "namespace" : "io.deephaven.examples",\n              "name" : "share_price",\n              "fields" : [\n                { "name" : "Symbol", "type" : "string" },\n                { "name" : "Side",   "type" : "string" },\n                { "name" : "Qty",    "type" : "int"    },\n                { "name" : "Price",  "type" : "double" }\n              ]\n            }\n            '
    schema_str = ('{ "schema" : "%s" }' % schema.replace('\n', ' ').replace('"', '\\"'))
    sys_str = ("\n            curl -X POST                 -H 'Content-type: application/vnd.schemaregistry.v1+json; artifactType=AVRO'                 --data-binary '%s'                 http://redpanda:8081/subjects/share_price_record/versions\n            " % schema_str)
    r = os.system(sys_str)
    self.assertEqual(0, r)
    with self.subTest(msg='straight schema, no mapping'):
        t = ck.consume({'bootstrap.servers': 'redpanda:29092', 'schema.registry.url': 'http://redpanda:8081'}, 'share_price', key_spec=KeyValueSpec.IGNORE, value_spec=ck.avro_spec('share_price_record', schema_version='1'), table_type=TableType.append())
        cols = t.columns
        self.assertEqual(7, len(cols))
        self._assert_common_cols(cols)
        self.assertEqual('Symbol', cols[3].name)
        self.assertEqual(dtypes.string, cols[3].data_type)
        self.assertEqual('Side', cols[4].name)
        self.assertEqual(dtypes.string, cols[4].data_type)
        self.assertEqual('Qty', cols[5].name)
        self.assertEqual(dtypes.int32, cols[5].data_type)
        self.assertEqual('Price', cols[6].name)
        self.assertEqual(dtypes.double, cols[6].data_type)
    with self.subTest(msg='mapping_only (filter out some schema fields)'):
        m = {'Symbol': 'Ticker', 'Price': 'Dollars'}
        t = ck.consume({'bootstrap.servers': 'redpanda:29092', 'schema.registry.url': 'http://redpanda:8081'}, 'share_price', key_spec=KeyValueSpec.IGNORE, value_spec=ck.avro_spec('share_price_record', mapping=m, mapped_only=True), table_type=TableType.append())
        cols = t.columns
        self.assertEqual(5, len(cols))
        self._assert_common_cols(cols)
        self.assertEqual('Ticker', cols[3].name)
        self.assertEqual(dtypes.string, cols[3].data_type)
        self.assertEqual('Dollars', cols[4].name)
        self.assertEqual(dtypes.double, cols[4].data_type)
    with self.subTest(msg='mapping (rename some fields)'):
        m = {'Symbol': 'Ticker', 'Qty': 'Quantity'}
        t = ck.consume({'bootstrap.servers': 'redpanda:29092', 'schema.registry.url': 'http://redpanda:8081'}, 'share_price', key_spec=KeyValueSpec.IGNORE, value_spec=ck.avro_spec('share_price_record', mapping=m), table_type=TableType.append())
        cols = t.columns
        self.assertEqual(7, len(cols))
        self._assert_common_cols(cols)
        self.assertEqual('Ticker', cols[3].name)
        self.assertEqual(dtypes.string, cols[3].data_type)
        self.assertEqual('Side', cols[4].name)
        self.assertEqual(dtypes.string, cols[4].data_type)
        self.assertEqual('Quantity', cols[5].name)
        self.assertEqual(dtypes.int32, cols[5].data_type)
        self.assertEqual('Price', cols[6].name)
        self.assertEqual(dtypes.double, cols[6].data_type)