forked from apache/carbondata
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#22 from QiangCai/wfmaster
carbon api for spark2
- Loading branch information
Showing
8 changed files
with
382 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
integration/spark2/src/main/scala/org/apache/spark/util/CleanFiles.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.util | ||
|
||
import org.apache.spark.sql.execution.command.{CleanFiles => TableCleanFiles} | ||
import org.apache.spark.sql.{CarbonEnv, SparkSession} | ||
|
||
/** | ||
* clean files api | ||
*/ | ||
object CleanFiles { | ||
|
||
def cleanFiles(spark: SparkSession, dbName: Option[String], tableName: String): Unit = { | ||
TableCleanFiles(dbName, tableName).run(spark) | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
|
||
if (args.length < 2) { | ||
System.err.println("Usage: TableCleanFiles <store path> <table name>"); | ||
System.exit(1) | ||
} | ||
|
||
val storePath = TableAPIUtil.escape(args(0)) | ||
val (dbName, tableName) = TableAPIUtil.parseSchemaName(TableAPIUtil.escape(args(1))) | ||
val spark = TableAPIUtil.spark(storePath, s"TableCleanFiles: $dbName.$tableName") | ||
CarbonEnv.init(spark.sqlContext) | ||
cleanFiles(spark, Option(dbName), tableName) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
integration/spark2/src/main/scala/org/apache/spark/util/Compaction.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.util | ||
|
||
import org.apache.spark.sql.{CarbonEnv, SparkSession} | ||
import org.apache.spark.sql.execution.command.{AlterTableCompaction, AlterTableModel} | ||
|
||
/** | ||
* table compaction api | ||
*/ | ||
object Compaction { | ||
|
||
def compaction(spark: SparkSession, dbName: Option[String], tableName: String, | ||
compactionType: String): Unit = { | ||
AlterTableCompaction(AlterTableModel(dbName, tableName, compactionType, "")).run(spark) | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
if (args.length < 3) { | ||
System.err.println("Usage: TableCompaction <store path> <table name> <major|minor>"); | ||
System.exit(1) | ||
} | ||
|
||
val storePath = TableAPIUtil.escape(args(0)) | ||
val (dbName, tableName) = TableAPIUtil.parseSchemaName(TableAPIUtil.escape(args(1))) | ||
val compactionType = TableAPIUtil.escape(args(2)) | ||
val spark = TableAPIUtil.spark(storePath, s"TableCompaction: $dbName.$tableName") | ||
CarbonEnv.init(spark.sqlContext) | ||
compaction(spark, Option(dbName), tableName, compactionType) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
integration/spark2/src/main/scala/org/apache/spark/util/DeleteSegmentByDate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.apache.spark.util | ||
|
||
import org.apache.spark.sql.{CarbonEnv, SparkSession} | ||
import org.apache.spark.sql.execution.command.DeleteLoadsByLoadDate | ||
|
||
/** | ||
* delete segments before some date | ||
*/ | ||
object DeleteSegmentByDate { | ||
|
||
def deleteSegmentByDate(spark: SparkSession, dbName: Option[String], tableName: String, | ||
dateValue: String): Unit = { | ||
DeleteLoadsByLoadDate(dbName, tableName, "", dateValue).run(spark) | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
if (args.length < 3) { | ||
System.err.println( | ||
"Usage: TableDeleteSegmentByDate <store path> <table name> <before date value>"); | ||
System.exit(1) | ||
} | ||
|
||
val storePath = TableAPIUtil.escape(args(0)) | ||
val (dbName, tableName) = TableAPIUtil.parseSchemaName(TableAPIUtil.escape(args(1))) | ||
val dateValue = TableAPIUtil.escape(args(2)) | ||
val spark = TableAPIUtil.spark(storePath, s"TableCleanFiles: $dbName.$tableName") | ||
CarbonEnv.init(spark.sqlContext) | ||
deleteSegmentByDate(spark, Option(dbName), tableName, dateValue) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
integration/spark2/src/main/scala/org/apache/spark/util/DeleteSegmentById.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.apache.spark.util | ||
|
||
import org.apache.spark.sql.{CarbonEnv, SparkSession} | ||
import org.apache.spark.sql.execution.command.DeleteLoadsById | ||
|
||
/** | ||
* delete segments by id list | ||
*/ | ||
object DeleteSegmentById { | ||
|
||
def extractSegmentIds(segmentIds: String): Seq[String] = { | ||
segmentIds.split(",").toSeq | ||
} | ||
|
||
def deleteSegmentById(spark: SparkSession, dbName: Option[String], tableName: String, | ||
segmentIds: Seq[String]): Unit = { | ||
DeleteLoadsById(segmentIds, dbName, tableName).run(spark) | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
|
||
if (args.length < 3) { | ||
System.err.println( | ||
"Usage: TableDeleteSegmentByID <store path> <table name> <segment id list>"); | ||
System.exit(1) | ||
} | ||
|
||
val storePath = TableAPIUtil.escape(args(0)) | ||
val (dbName, tableName) = TableAPIUtil.parseSchemaName(TableAPIUtil.escape(args(1))) | ||
val segmentIds = extractSegmentIds(TableAPIUtil.escape(args(2))) | ||
val spark = TableAPIUtil.spark(storePath, s"TableDeleteSegmentById: $dbName.$tableName") | ||
CarbonEnv.init(spark.sqlContext) | ||
deleteSegmentById(spark, Option(dbName), tableName, segmentIds) | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
integration/spark2/src/main/scala/org/apache/spark/util/ShowSegments.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.util | ||
|
||
import org.apache.commons.lang3.StringUtils | ||
import org.apache.spark.sql.catalyst.expressions.AttributeReference | ||
import org.apache.spark.sql.execution.command.ShowLoads | ||
import org.apache.spark.sql.types.{StringType, TimestampType} | ||
import org.apache.spark.sql.{CarbonEnv, Row, SparkSession} | ||
|
||
object ShowSegments { | ||
|
||
def showSegments(spark: SparkSession, dbName: Option[String], tableName: String, | ||
limit: Option[String]): Seq[Row] = { | ||
val output = Seq(AttributeReference("SegmentSequenceId", StringType, nullable = false)(), | ||
AttributeReference("Status", StringType, nullable = false)(), | ||
AttributeReference("Load Start Time", TimestampType, nullable = false)(), | ||
AttributeReference("Load End Time", TimestampType, nullable = false)()) | ||
ShowLoads(dbName, tableName, limit: Option[String], output).run(spark) | ||
} | ||
|
||
def showString(rows: Seq[Row]): String = { | ||
val sb = new StringBuilder | ||
sb.append("+-----------------+---------------+---------------------+---------------------+\n") | ||
.append("|SegmentSequenceId|Status |Load Start Time |Load End Time |\n") | ||
.append("+-----------------+---------------+---------------------+---------------------+\n") | ||
rows.foreach{row => | ||
sb.append("|") | ||
.append(StringUtils.rightPad(row.getString(0), 17)) | ||
.append("|") | ||
.append(StringUtils.rightPad(row.getString(1).substring(0, 15), 15)) | ||
.append("|") | ||
.append(row.getAs[java.sql.Timestamp](2).formatted("yyyy-MM-dd HH:mm:ss.s")) | ||
.append("|") | ||
.append(row.getAs[java.sql.Timestamp](3).formatted("yyyy-MM-dd HH:mm:ss.s")) | ||
.append("|\n") | ||
} | ||
sb.append("+-----------------+---------------+---------------------+---------------------+\n") | ||
sb.toString | ||
} | ||
|
||
def parseLimit(limit: String): Int = { | ||
Integer.parseInt(limit) | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
|
||
if (args.length < 2) { | ||
System.err.println("Usage: ShowSegments <store path> <table name> [limit]"); | ||
System.exit(1) | ||
} | ||
|
||
val storePath = TableAPIUtil.escape(args(0)) | ||
val (dbName, tableName) = TableAPIUtil.parseSchemaName(TableAPIUtil.escape(args(1))) | ||
|
||
val limit = if (args.length >= 3 ) { | ||
Some(TableAPIUtil.escape(args(2))) | ||
} else { | ||
None | ||
} | ||
val spark = TableAPIUtil.spark(storePath, s"TableCleanFiles: $dbName.$tableName") | ||
CarbonEnv.init(spark.sqlContext) | ||
val rows = showSegments(spark, Option(dbName), tableName, limit) | ||
System.out.println(showString(rows)) | ||
} | ||
} |
Oops, something went wrong.