You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@carbondata.apache.org by xubo245 <gi...@git.apache.org> on 2018/01/23 04:21:27 UTC

[GitHub] carbondata pull request #1565: [CARBONDATA-1518][Pre-Aggregate]Support creat...

Github user xubo245 commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1565#discussion_r163140389
  
    --- Diff: integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/timeseries/TimeseriesUtil.scala ---
    @@ -0,0 +1,159 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.spark.sql.execution.command.timeseries
    +
    +import java.sql.Timestamp
    +
    +import org.apache.spark.sql.execution.command.{DataMapField, Field}
    +
    +import org.apache.carbondata.core.constants.CarbonCommonConstants
    +import org.apache.carbondata.core.metadata.datatype.DataTypes
    +import org.apache.carbondata.core.metadata.schema.table.CarbonTable
    +import org.apache.carbondata.core.preagg.TimeSeriesUDF
    +import org.apache.carbondata.spark.exception.MalformedCarbonCommandException
    +
    +/**
    + * Utility class for time series to keep
    + */
    +object TimeSeriesUtil {
    +
    +  /**
    +   * Below method will be used to validate whether column mentioned in time series
    +   * is timestamp column or not
    +   *
    +   * @param dmproperties
    +   * data map properties
    +   * @param parentTable
    +   * parent table
    +   * @return whether time stamp column
    +   */
    +  def validateTimeSeriesEventTime(dmproperties: Map[String, String],
    +      parentTable: CarbonTable) {
    +    val eventTime = dmproperties.get(CarbonCommonConstants.TIMESERIES_EVENTTIME)
    +    if (!eventTime.isDefined) {
    +      throw new MalformedCarbonCommandException("Eventtime not defined in time series")
    +    } else {
    +      val carbonColumn = parentTable.getColumnByName(parentTable.getTableName, eventTime.get)
    +      if (carbonColumn.getDataType != DataTypes.TIMESTAMP) {
    +        throw new MalformedCarbonCommandException(
    +          "Timeseries event time is only supported on Timestamp " +
    +          "column")
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Below method will be used to validate the hierarchy of time series and its value
    +   * validation will be done whether hierarchy order is proper or not and hierarchy level
    +   * value
    +   *
    +   * @param timeSeriesHierarchyDetails
    +   * time series hierarchy string
    +   */
    +  def validateAndGetTimeSeriesHierarchyDetails(timeSeriesHierarchyDetails: String): Array[
    +    (String, String)] = {
    +    val updatedtimeSeriesHierarchyDetails = timeSeriesHierarchyDetails.toLowerCase
    +    val timeSeriesHierarchy = updatedtimeSeriesHierarchyDetails.split(",")
    +    val hierBuffer = timeSeriesHierarchy.map {
    +      case f =>
    +        val splits = f.split("=")
    +        // checking hierarchy name is valid or not
    +        if (!TimeSeriesUDF.INSTANCE.TIMESERIES_FUNCTION.contains(splits(0).toLowerCase)) {
    +          throw new MalformedCarbonCommandException(s"Not supported heirarchy type: ${ splits(0) }")
    --- End diff --
    
    should heirarchy be hierarchy?


---