Repository: phoenix Updated Branches: refs/heads/4.x-HBase-0.98 b0f87aaf4 -> 7133294c9
Fixed date generation pattern Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/7133294c Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/7133294c Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/7133294c Branch: refs/heads/4.x-HBase-0.98 Commit: 7133294c91b07ee65ebd23d91e56527350684f3c Parents: b0f87aa Author: Karan Singhal <karan24...@gmail.com> Authored: Wed Dec 23 16:21:09 2015 +0530 Committer: Cody Marcel <cmar...@salesforce.com> Committed: Wed Jan 6 10:17:52 2016 -0800 ---------------------------------------------------------------------- .../apache/phoenix/pherf/PherfConstants.java | 5 ++- .../phoenix/pherf/rules/RulesApplier.java | 47 ++++++++++++++------ .../test/resources/scenario/test_scenario.xml | 6 +-- 3 files changed, 40 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/7133294c/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java index c3a1200..42b5d21 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java @@ -18,6 +18,8 @@ package org.apache.phoenix.pherf; +import org.joda.time.DateTimeZone; + import java.io.IOException; import java.io.InputStream; import java.util.Properties; @@ -38,7 +40,8 @@ public class PherfConstants { public static final int DEFAULT_THREAD_POOL_SIZE = 10; public static final int DEFAULT_BATCH_SIZE = 1000; - public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS"; + public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS z"; + public static final DateTimeZone DEFAULT_TIME_ZONE = DateTimeZone.UTC; public static final String RESOURCE_SCENARIO = "/scenario"; public static final String SCENARIO_ROOT_PATTERN = http://git-wip-us.apache.org/repos/asf/phoenix/blob/7133294c/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/rules/RulesApplier.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/rules/RulesApplier.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/rules/RulesApplier.java index 2b1689a..68791ce 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/rules/RulesApplier.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/rules/RulesApplier.java @@ -196,6 +196,8 @@ public class RulesApplier { case DATE: if ((column.getDataValues() != null) && (column.getDataValues().size() > 0)) { data = pickDataValueFromList(dataValues); + // Check if date has right format or not + data.setValue(checkDatePattern(data.getValue())); } else { int minYear = column.getMinValue(); int maxYear = column.getMaxValue(); @@ -203,6 +205,8 @@ public class RulesApplier { String dt = generateRandomDate(minYear, maxYear); data = new DataValue(column.getType(), dt); + data.setMaxValue(String.valueOf(minYear)); + data.setMinValue(String.valueOf(maxYear)); } break; default: @@ -213,28 +217,26 @@ public class RulesApplier { return data; } - public String generateRandomDate(int min, int max) { - int year = RandomUtils.nextInt(min, max); - int month = RandomUtils.nextInt(0, 11); - int day = RandomUtils.nextInt(0, 31); - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, year); - calendar.set(Calendar.MONTH, month); - calendar.set(Calendar.DAY_OF_MONTH, day); - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); - - return df.format(calendar.getTime()); + // Convert years into standard date format yyyy-MM-dd HH:mm:ss.SSS z + public String generateRandomDate(int min, int max) throws Exception { + String mindt = min + "-01-01 00:00:00.000"; // set min date as starting of min year + String maxdt = max + "-12-31 23:59:59.999"; // set max date as end of max year + return generateRandomDate(mindt, maxdt); } public String generateRandomDate(String min, String max) throws Exception { DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN); - DateTime minDt = fmtr.parseDateTime(min); - DateTime maxDt = fmtr.parseDateTime(max); + DateTime minDt; + DateTime maxDt; DateTime dt; + + minDt = fmtr.parseDateTime(checkDatePattern(min)); + maxDt = fmtr.parseDateTime(checkDatePattern(max)); + // Get Ms Date between min and max synchronized (randomDataGenerator) { long rndLong = randomDataGenerator.nextLong(minDt.getMillis(), maxDt.getMillis()); - dt = new DateTime(rndLong, minDt.getZone()); + dt = new DateTime(rndLong, PherfConstants.DEFAULT_TIME_ZONE); } return fmtr.print(dt); @@ -297,9 +299,26 @@ public class RulesApplier { retValue.setValue(generateRandomDate(retValue.getMinValue(), retValue.getMaxValue())); + retValue.setValue(generateRandomDate(retValue.getMinValue(), retValue.getMaxValue())); + retValue.setMinValue(checkDatePattern(valueRule.getMinValue())); + retValue.setMaxValue(checkDatePattern(valueRule.getMaxValue())); return retValue; } + // Checks if date is in defult pattern + public String checkDatePattern(String date) { + DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN); + DateTime parsedDate; + try { + parsedDate = fmtr.parseDateTime(date); + } catch (IllegalArgumentException e) { + /* Trying add default time zone if no time zone appended to date */ + date = date + " " + PherfConstants.DEFAULT_TIME_ZONE.toString(); + parsedDate = fmtr.parseDateTime(date); + } + return fmtr.print(parsedDate); + } + /** * Top level {@link java.util.List} {@link java.util.Map}. This will likely only have one entry until we have * multiple files. http://git-wip-us.apache.org/repos/asf/phoenix/blob/7133294c/phoenix-pherf/src/test/resources/scenario/test_scenario.xml ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/test/resources/scenario/test_scenario.xml b/phoenix-pherf/src/test/resources/scenario/test_scenario.xml index def55ca..3438db4 100644 --- a/phoenix-pherf/src/test/resources/scenario/test_scenario.xml +++ b/phoenix-pherf/src/test/resources/scenario/test_scenario.xml @@ -82,11 +82,11 @@ <maxValue>2019-09-15 11:00:00.000</maxValue> </datavalue> <datavalue distribution="10"> - <value>2019-09-19 00:01:00</value> + <value>2019-09-19 00:01:00.000</value> </datavalue> <datavalue distribution="10"> - <minValue>2019-09-22 00:01:00.000</minValue> - <maxValue>2019-09-22 00:01:00.300</maxValue> + <minValue>2019-09-22 00:01:00.000 UTC</minValue> + <maxValue>2019-09-22 00:01:00.300 UTC</maxValue> </datavalue> </valuelist> </column>