[GitHub] carbondata pull request #1472: [CARBONDATA-1618]Table comment support for al...

2017-11-08 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/carbondata/pull/1472


---


[GitHub] carbondata pull request #1472: [CARBONDATA-1618]Table comment support for al...

2017-11-07 Thread pawanmalwal
Github user pawanmalwal commented on a diff in the pull request:

https://github.com/apache/carbondata/pull/1472#discussion_r14959
  
--- Diff: 
core/src/main/java/org/apache/carbondata/core/constants/CarbonCommonConstants.java
 ---
@@ -1374,6 +1374,12 @@
   @CarbonProperty
   public static final String BITSET_PIPE_LINE = 
"carbon.use.bitset.pipe.line";
 
+  /**
+   * this will be used to provide comment for table
+   */
+  @CarbonProperty
--- End diff --

Done. 


---


[GitHub] carbondata pull request #1472: [CARBONDATA-1618]Table comment support for al...

2017-11-07 Thread pawanmalwal
Github user pawanmalwal commented on a diff in the pull request:

https://github.com/apache/carbondata/pull/1472#discussion_r149593291
  
--- Diff: 
integration/spark2/src/main/scala/org/apache/spark/util/AlterTableUtil.scala ---
@@ -317,4 +321,84 @@ object AlterTableUtil {
 }
   }
 
+  /**
+   * This method add/modify the table comments.
+   *
+   * @param tableIdentifier
+   * @param properties
+   * @param propKeys
+   * @param set
+   * @param sparkSession
+   * @param sessionState
+   */
+  def modifyTableComment(tableIdentifier: TableIdentifier, properties: 
Map[String, String],
+ propKeys: Seq[String], set: Boolean)
+(sparkSession: SparkSession, sessionState: 
CarbonSessionState): Unit = {
+val tableName = tableIdentifier.table
+val dbName = 
tableIdentifier.database.getOrElse(sparkSession.catalog.currentDatabase)
+LOGGER.audit(s"Alter table comment request has been received for 
$dbName.$tableName")
+val locksToBeAcquired = List(LockUsage.METADATA_LOCK, 
LockUsage.COMPACTION_LOCK)
+var locks = List.empty[ICarbonLock]
+var timeStamp = 0L
+var newCols = 
Seq[org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema]()
+var carbonTable: CarbonTable = null
+try {
+  locks = AlterTableUtil
+.validateTableAndAcquireLock(dbName, tableName, 
locksToBeAcquired)(sparkSession)
+  val metastore = CarbonEnv.getInstance(sparkSession).carbonMetastore
+  carbonTable = metastore
+.lookupRelation(Some(dbName), 
tableName)(sparkSession).asInstanceOf[CarbonRelation]
+.tableMeta.carbonTable
+  // get the latest carbon table
+  // read the latest schema file
+  val carbonTablePath = 
CarbonStorePath.getCarbonTablePath(carbonTable.getStorePath,
+carbonTable.getCarbonTableIdentifier)
+  val thriftTableInfo: TableInfo = 
metastore.getThriftTableInfo(carbonTablePath)(sparkSession)
+  val schemaConverter = new ThriftWrapperSchemaConverterImpl()
+  val wrapperTableInfo = schemaConverter
+.fromExternalToWrapperTableInfo(thriftTableInfo,
+  dbName,
+  tableName,
+  carbonTable.getStorePath)
+  val schemaEvolutionEntry = new 
org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry
+  schemaEvolutionEntry.setTimeStamp(timeStamp)
+  val thriftTable = schemaConverter
+.fromWrapperToExternalTableInfo(wrapperTableInfo, dbName, 
tableName)
+  val tblPropertiesMap: mutable.Map[String, String] =
+thriftTable.fact_table.getTableProperties.asScala
+  if (set) {
+//   This overrides old properties and update the comment 
parameter of thriftTable
+//   with the newly added/modified comment since thriftTable 
also holds comment as its
+//   direct property.
+
+properties.foreach {
+  x =>
--- End diff --

Done.


---


[GitHub] carbondata pull request #1472: [CARBONDATA-1618]Table comment support for al...

2017-11-07 Thread pawanmalwal
Github user pawanmalwal commented on a diff in the pull request:

https://github.com/apache/carbondata/pull/1472#discussion_r149593267
  
--- Diff: 
integration/spark2/src/main/scala/org/apache/spark/util/AlterTableUtil.scala ---
@@ -317,4 +321,84 @@ object AlterTableUtil {
 }
   }
 
+  /**
+   * This method add/modify the table comments.
+   *
+   * @param tableIdentifier
+   * @param properties
+   * @param propKeys
+   * @param set
+   * @param sparkSession
+   * @param sessionState
+   */
+  def modifyTableComment(tableIdentifier: TableIdentifier, properties: 
Map[String, String],
+ propKeys: Seq[String], set: Boolean)
+(sparkSession: SparkSession, sessionState: 
CarbonSessionState): Unit = {
+val tableName = tableIdentifier.table
+val dbName = 
tableIdentifier.database.getOrElse(sparkSession.catalog.currentDatabase)
+LOGGER.audit(s"Alter table comment request has been received for 
$dbName.$tableName")
+val locksToBeAcquired = List(LockUsage.METADATA_LOCK, 
LockUsage.COMPACTION_LOCK)
+var locks = List.empty[ICarbonLock]
+var timeStamp = 0L
+var newCols = 
Seq[org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema]()
+var carbonTable: CarbonTable = null
+try {
+  locks = AlterTableUtil
+.validateTableAndAcquireLock(dbName, tableName, 
locksToBeAcquired)(sparkSession)
+  val metastore = CarbonEnv.getInstance(sparkSession).carbonMetastore
+  carbonTable = metastore
+.lookupRelation(Some(dbName), 
tableName)(sparkSession).asInstanceOf[CarbonRelation]
+.tableMeta.carbonTable
+  // get the latest carbon table
+  // read the latest schema file
+  val carbonTablePath = 
CarbonStorePath.getCarbonTablePath(carbonTable.getStorePath,
+carbonTable.getCarbonTableIdentifier)
+  val thriftTableInfo: TableInfo = 
metastore.getThriftTableInfo(carbonTablePath)(sparkSession)
+  val schemaConverter = new ThriftWrapperSchemaConverterImpl()
+  val wrapperTableInfo = schemaConverter
+.fromExternalToWrapperTableInfo(thriftTableInfo,
+  dbName,
+  tableName,
+  carbonTable.getStorePath)
+  val schemaEvolutionEntry = new 
org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry
+  schemaEvolutionEntry.setTimeStamp(timeStamp)
+  val thriftTable = schemaConverter
+.fromWrapperToExternalTableInfo(wrapperTableInfo, dbName, 
tableName)
+  val tblPropertiesMap: mutable.Map[String, String] =
+thriftTable.fact_table.getTableProperties.asScala
+  if (set) {
+//   This overrides old properties and update the comment 
parameter of thriftTable
+//   with the newly added/modified comment since thriftTable 
also holds comment as its
+//   direct property.
+
+properties.foreach {
+  x =>
+if 
(x._1.equalsIgnoreCase(CarbonCommonConstants.TABLE_COMMENT)) {
+  tblPropertiesMap.put(x._1, x._2)
+}
+}
+  } else {
+// This removes the comment parameter from thriftTable
+// since thriftTable also holds comment as its property.
+propKeys.foreach {
+  x =>
--- End diff --

Done.


---


[GitHub] carbondata pull request #1472: [CARBONDATA-1618]Table comment support for al...

2017-11-07 Thread ravipesala
Github user ravipesala commented on a diff in the pull request:

https://github.com/apache/carbondata/pull/1472#discussion_r149587728
  
--- Diff: 
integration/spark2/src/main/scala/org/apache/spark/util/AlterTableUtil.scala ---
@@ -317,4 +321,84 @@ object AlterTableUtil {
 }
   }
 
+  /**
+   * This method add/modify the table comments.
+   *
+   * @param tableIdentifier
+   * @param properties
+   * @param propKeys
+   * @param set
+   * @param sparkSession
+   * @param sessionState
+   */
+  def modifyTableComment(tableIdentifier: TableIdentifier, properties: 
Map[String, String],
+ propKeys: Seq[String], set: Boolean)
+(sparkSession: SparkSession, sessionState: 
CarbonSessionState): Unit = {
+val tableName = tableIdentifier.table
+val dbName = 
tableIdentifier.database.getOrElse(sparkSession.catalog.currentDatabase)
+LOGGER.audit(s"Alter table comment request has been received for 
$dbName.$tableName")
+val locksToBeAcquired = List(LockUsage.METADATA_LOCK, 
LockUsage.COMPACTION_LOCK)
+var locks = List.empty[ICarbonLock]
+var timeStamp = 0L
+var newCols = 
Seq[org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema]()
+var carbonTable: CarbonTable = null
+try {
+  locks = AlterTableUtil
+.validateTableAndAcquireLock(dbName, tableName, 
locksToBeAcquired)(sparkSession)
+  val metastore = CarbonEnv.getInstance(sparkSession).carbonMetastore
+  carbonTable = metastore
+.lookupRelation(Some(dbName), 
tableName)(sparkSession).asInstanceOf[CarbonRelation]
+.tableMeta.carbonTable
+  // get the latest carbon table
+  // read the latest schema file
+  val carbonTablePath = 
CarbonStorePath.getCarbonTablePath(carbonTable.getStorePath,
+carbonTable.getCarbonTableIdentifier)
+  val thriftTableInfo: TableInfo = 
metastore.getThriftTableInfo(carbonTablePath)(sparkSession)
+  val schemaConverter = new ThriftWrapperSchemaConverterImpl()
+  val wrapperTableInfo = schemaConverter
+.fromExternalToWrapperTableInfo(thriftTableInfo,
+  dbName,
+  tableName,
+  carbonTable.getStorePath)
+  val schemaEvolutionEntry = new 
org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry
+  schemaEvolutionEntry.setTimeStamp(timeStamp)
+  val thriftTable = schemaConverter
+.fromWrapperToExternalTableInfo(wrapperTableInfo, dbName, 
tableName)
+  val tblPropertiesMap: mutable.Map[String, String] =
+thriftTable.fact_table.getTableProperties.asScala
+  if (set) {
+//   This overrides old properties and update the comment 
parameter of thriftTable
+//   with the newly added/modified comment since thriftTable 
also holds comment as its
+//   direct property.
+
+properties.foreach {
+  x =>
+if 
(x._1.equalsIgnoreCase(CarbonCommonConstants.TABLE_COMMENT)) {
+  tblPropertiesMap.put(x._1, x._2)
+}
+}
+  } else {
+// This removes the comment parameter from thriftTable
+// since thriftTable also holds comment as its property.
+propKeys.foreach {
+  x =>
--- End diff --

move this to above line like properties.foreach { x =>


---


[GitHub] carbondata pull request #1472: [CARBONDATA-1618]Table comment support for al...

2017-11-07 Thread ravipesala
Github user ravipesala commented on a diff in the pull request:

https://github.com/apache/carbondata/pull/1472#discussion_r149587610
  
--- Diff: 
integration/spark2/src/main/scala/org/apache/spark/util/AlterTableUtil.scala ---
@@ -317,4 +321,84 @@ object AlterTableUtil {
 }
   }
 
+  /**
+   * This method add/modify the table comments.
+   *
+   * @param tableIdentifier
+   * @param properties
+   * @param propKeys
+   * @param set
+   * @param sparkSession
+   * @param sessionState
+   */
+  def modifyTableComment(tableIdentifier: TableIdentifier, properties: 
Map[String, String],
+ propKeys: Seq[String], set: Boolean)
+(sparkSession: SparkSession, sessionState: 
CarbonSessionState): Unit = {
+val tableName = tableIdentifier.table
+val dbName = 
tableIdentifier.database.getOrElse(sparkSession.catalog.currentDatabase)
+LOGGER.audit(s"Alter table comment request has been received for 
$dbName.$tableName")
+val locksToBeAcquired = List(LockUsage.METADATA_LOCK, 
LockUsage.COMPACTION_LOCK)
+var locks = List.empty[ICarbonLock]
+var timeStamp = 0L
+var newCols = 
Seq[org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema]()
+var carbonTable: CarbonTable = null
+try {
+  locks = AlterTableUtil
+.validateTableAndAcquireLock(dbName, tableName, 
locksToBeAcquired)(sparkSession)
+  val metastore = CarbonEnv.getInstance(sparkSession).carbonMetastore
+  carbonTable = metastore
+.lookupRelation(Some(dbName), 
tableName)(sparkSession).asInstanceOf[CarbonRelation]
+.tableMeta.carbonTable
+  // get the latest carbon table
+  // read the latest schema file
+  val carbonTablePath = 
CarbonStorePath.getCarbonTablePath(carbonTable.getStorePath,
+carbonTable.getCarbonTableIdentifier)
+  val thriftTableInfo: TableInfo = 
metastore.getThriftTableInfo(carbonTablePath)(sparkSession)
+  val schemaConverter = new ThriftWrapperSchemaConverterImpl()
+  val wrapperTableInfo = schemaConverter
+.fromExternalToWrapperTableInfo(thriftTableInfo,
+  dbName,
+  tableName,
+  carbonTable.getStorePath)
+  val schemaEvolutionEntry = new 
org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry
+  schemaEvolutionEntry.setTimeStamp(timeStamp)
+  val thriftTable = schemaConverter
+.fromWrapperToExternalTableInfo(wrapperTableInfo, dbName, 
tableName)
+  val tblPropertiesMap: mutable.Map[String, String] =
+thriftTable.fact_table.getTableProperties.asScala
+  if (set) {
+//   This overrides old properties and update the comment 
parameter of thriftTable
+//   with the newly added/modified comment since thriftTable 
also holds comment as its
+//   direct property.
+
+properties.foreach {
+  x =>
--- End diff --

move this to above line like properties.foreach { x =>


---


[GitHub] carbondata pull request #1472: [CARBONDATA-1618]Table comment support for al...

2017-11-07 Thread ravipesala
Github user ravipesala commented on a diff in the pull request:

https://github.com/apache/carbondata/pull/1472#discussion_r149587321
  
--- Diff: 
core/src/main/java/org/apache/carbondata/core/constants/CarbonCommonConstants.java
 ---
@@ -1374,6 +1374,12 @@
   @CarbonProperty
   public static final String BITSET_PIPE_LINE = 
"carbon.use.bitset.pipe.line";
 
+  /**
+   * this will be used to provide comment for table
+   */
+  @CarbonProperty
--- End diff --

its not a carbon property, it is just a constant


---