From 7dbd1dfbd29ec4ffac1499f0249fd9f77907d8cb Mon Sep 17 00:00:00 2001 From: Muga Nishizawa Date: Thu, 13 Jul 2017 14:33:14 -0700 Subject: [PATCH] Add unit test for column based timezone option --- .../TestExpandJsonFilterPlugin.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/test/java/org/embulk/filter/expand_json/TestExpandJsonFilterPlugin.java b/src/test/java/org/embulk/filter/expand_json/TestExpandJsonFilterPlugin.java index 77bfb77..50eb2c6 100644 --- a/src/test/java/org/embulk/filter/expand_json/TestExpandJsonFilterPlugin.java +++ b/src/test/java/org/embulk/filter/expand_json/TestExpandJsonFilterPlugin.java @@ -427,6 +427,51 @@ public void run(TaskSource taskSource, Schema outputSchema) }); } + @Test + public void testColumnBasedTimezone() + { + String configYaml = "" + + "type: expand_json\n" + + "json_column_name: _c0\n" + + "root: $.\n" + + "expanded_columns:\n" + + " - {name: _j0, type: timestamp, format: '%Y-%m-%d %H:%M:%S %z'}\n" + + " - {name: _j1, type: timestamp, format: '%Y-%m-%d %H:%M:%S', timezone: 'Asia/Tokyo'}\n"; + + ConfigSource config = getConfigFromYaml(configYaml); + final Schema schema = schema("_c0", JSON, "_c1", STRING); + + expandJsonFilterPlugin.transaction(config, schema, new Control() + { + @Override + public void run(TaskSource taskSource, Schema outputSchema) + { + MockPageOutput mockPageOutput = new MockPageOutput(); + Value data = newMapBuilder() + .put(s("_j0"), s("2014-10-21 04:44:33 +0000")) + .put(s("_j1"), s("2014-10-21 04:44:33")) + .build(); + + try (PageOutput pageOutput = expandJsonFilterPlugin.open(taskSource, schema, outputSchema, mockPageOutput)) { + for (Page page : PageTestUtils.buildPage(runtime.getBufferAllocator(), schema, data, c1Data)) { + pageOutput.add(page); + } + + pageOutput.finish(); + } + + PageReader pageReader = new PageReader(outputSchema); + + for (Page page : mockPageOutput.pages) { + pageReader.setPage(page); + assertEquals("2014-10-21 04:44:33 UTC", pageReader.getTimestamp(outputSchema.getColumn(0)).toString()); + assertEquals("2014-10-20 19:44:33 UTC", pageReader.getTimestamp(outputSchema.getColumn(1)).toString()); + assertEquals(c1Data, pageReader.getString(outputSchema.getColumn(2))); + } + } + }); + } + @Test public void testExpandJsonValuesFromJson() {