Github user xubo245 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/1865#discussion_r164328911
--- Diff:
integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/timeseries/TimeSeriesUtil.scala
---
@@ -54,6 +56,107 @@ object TimeSeriesUtil {
}
}
+ def getGranularityKey(dmProperties: Map[String, String]): String = {
+
+ if (dmProperties.get(YEAR.getName).isDefined) {
+ return YEAR.getName
+ }
+ if (dmProperties.get(MONTH.getName).isDefined) {
+ return MONTH.getName
+ }
+ if (dmProperties.get(DAY.getName).isDefined) {
+ return DAY.getName
+ }
+ if (dmProperties.get(HOUR.getName).isDefined) {
+ return HOUR.getName
+ }
+ if (dmProperties.get(MINUTE.getName).isDefined) {
+ return MINUTE.getName
+ }
+ if (dmProperties.get(SECOND.getName).isDefined) {
+ return SECOND.getName
+ }
+ throw new CarbonIllegalArgumentException(
+ s"${TIMESERIES.getName} should define time granularity")
+ }
+ def validateTimeSeriesGranularity(
+ dmProperties: Map[String, String],
+ dmClassName: String): Boolean = {
+ var sum = 0
+
+ if (dmProperties.get(YEAR.getName).isDefined) {
+ sum = sum + 1
+ }
+ if (dmProperties.get(MONTH.getName).isDefined) {
+ sum = sum + 1
+ }
+ if (dmProperties.get(DAY.getName).isDefined) {
+ sum = sum + 1
+ }
+ if (dmProperties.get(HOUR.getName).isDefined) {
+ sum = sum + 1
+ }
+ if (dmProperties.get(MINUTE.getName).isDefined) {
+ sum = sum + 1
+ }
+ if (dmProperties.get(SECOND.getName).isDefined) {
+ sum = sum + 1
+ }
+
+ val granularity = if (sum > 1 || sum < 0) {
+ throw new UnsupportedDataMapException(
+ s"Granularity only support one")
+ } else if (sum == 1) {
+ true
+ } else {
+ false
+ }
+
+ if (granularity && !dmClassName.equalsIgnoreCase(TIMESERIES.getName)) {
+ throw new CarbonIllegalArgumentException(
+ s"It should using ${TIMESERIES.getName}")
+ } else if (!granularity &&
dmClassName.equalsIgnoreCase(TIMESERIES.getName)) {
+ throw new CarbonIllegalArgumentException(
+ s"${TIMESERIES.getName} should define time granularity")
+ } else if (granularity) {
+ true
+ } else {
+ false
+ }
+ }
+
+ def getTimeSeriesGranularityDetails(
--- End diff --
ok, done
---