Skip to content

Commit

Permalink
change parsre
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay357089 committed Sep 23, 2016
1 parent 699d0a0 commit 0f45d51
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import org.apache.carbondata.core.carbon.metadata.datatype.{DataType => CarbonTy
class DataFrameFuncs(dataFrame: DataFrame) extends Logging {

/**
* Saves DataFrame as CarbonData files.
*/
*
* Saves DataFrame as CarbonData files.
*/
def saveAsCarbonFile(parameters: Map[String, String] = Map()): Unit = {
// To avoid derby problem, dataframe need to be writen and read using CarbonContext
require(dataFrame.sqlContext.isInstanceOf[CarbonContext],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CarbonSqlParser()
protected val ALL = carbonKeyWord("ALL")
protected val HIGH_CARDINALITY_DIMS = carbonKeyWord("NO_DICTIONARY")
protected val BEFORE = carbonKeyWord("BEFORE")
protected val EQUAL = carbonKeyWord("EQUAL")
protected val BY = carbonKeyWord("BY")
protected val CARDINALITY = carbonKeyWord("CARDINALITY")
protected val CASCADE = carbonKeyWord("CASCADE")
Expand Down Expand Up @@ -138,7 +139,6 @@ class CarbonSqlParser()
protected val DIMENSION = carbonKeyWord("DIMENSION")
protected val STARTTIME = carbonKeyWord("STARTTIME")
protected val SEGMENTS = carbonKeyWord("SEGMENTS")
protected val SEGMENT = carbonKeyWord("SEGMENT")

protected val STRING = carbonKeyWord("STRING")
protected val INTEGER = carbonKeyWord("INTEGER")
Expand Down Expand Up @@ -1181,23 +1181,21 @@ class CarbonSqlParser()
p.getClass.getSimpleName.equals("DecimalLit") } ) ^^ (_.chars)

protected lazy val deleteLoadsByID: Parser[LogicalPlan] =
DELETE ~> SEGMENT ~> repsep(segmentId, ",") ~ (FROM ~> TABLE ~>
(ident <~ ".").? ~ ident) <~
DELETE ~> FROM ~ TABLE ~> (ident <~ ".").? ~ ident ~
(WHERE ~> SEGMENTS ~> EQUAL ~> repsep(segmentId, ",")) <~
opt(";") ^^ {
case loadids ~ table => table match {
case databaseName ~ tableName =>
DeleteLoadsById(loadids, databaseName, tableName.toLowerCase())
}
case dbName ~ tableName ~ loadids =>
DeleteLoadsById(loadids, dbName, tableName.toLowerCase())
}

protected lazy val deleteLoadsByLoadDate: Parser[LogicalPlan] =
DELETE ~> SEGMENTS ~> FROM ~> TABLE ~> (ident <~ ".").? ~ ident ~
(WHERE ~> (STARTTIME <~ BEFORE) ~ stringLit) <~
DELETE ~> FROM ~> TABLE ~> (ident <~ ".").? ~ ident ~
(WHERE ~> SEGMENTS ~> (STARTTIME <~ BEFORE) ~ stringLit) <~
opt(";") ^^ {
case schema ~ table ~ condition =>
case database ~ table ~ condition =>
condition match {
case dateField ~ dateValue =>
DeleteLoadsByLoadDate(schema, table.toLowerCase(), dateField, dateValue)
DeleteLoadsByLoadDate(database, table.toLowerCase(), dateField, dateValue)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class DataCompactionNoDictionaryTest extends QueryTest with BeforeAndAfterAll {
sql("LOAD DATA LOCAL INPATH '" + csvFilePath1 + "' INTO TABLE nodictionaryCompaction " +
"OPTIONS('DELIMITER' = ',')"
)
sql("DELETE segment 0.1,3 FROM TABLE nodictionaryCompaction")
sql("DELETE FROM TABLE nodictionaryCompaction WHERE SEGMENTS EQUAL 0.1,3 ")
checkAnswer(
sql("select country from nodictionaryCompaction"),
Seq()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class MajorCompactionIgnoreInMinorTest extends QueryTest with BeforeAndAfterAll
*/
test("delete compacted segment and check status") {
try {
sql("delete segment 2 from table ignoremajor")
sql("delete from table ignoremajor where segments equal 2")
assert(false)
}
catch {
Expand Down Expand Up @@ -178,7 +178,7 @@ class MajorCompactionIgnoreInMinorTest extends QueryTest with BeforeAndAfterAll
*/
test("delete compacted segment by date and check status") {
sql(
"DELETE SEGMENTS FROM TABLE ignoremajor where STARTTIME before" +
"DELETE FROM TABLE ignoremajor where SEGMENTS STARTTIME before" +
" '2222-01-01 19:35:01'"
)
val segmentStatusManager: SegmentStatusManager = new SegmentStatusManager(new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TestLoadTblNameIsKeyword extends QueryTest with BeforeAndAfterAll {
LOAD DATA LOCAL INPATH '$testData' into table timestamp
""")
sql("show segments for table timestamp")
sql("delete segments from table timestamp where starttime before '2099-10-01 18:00:00'")
sql("delete from table timestamp where segments starttime before '2099-10-01 18:00:00'")
sql("clean files for table timestamp")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {
val actualValue: String = getSegmentStartTime(segments, 1)
// delete segments (0,1) which contains ind, aus
sql(
"DELETE SEGMENTS FROM TABLE DataRetentionTable where STARTTIME before '" + actualValue + "'")
"DELETE FROM TABLE DataRetentionTable where SEGMENTS STARTTIME before '" + actualValue + "'")

// load segment 2 which contains eng
sql(
Expand All @@ -158,7 +158,7 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {

test("RetentionTest3_DeleteByLoadId") {
// delete segment 2 and load ind segment
sql("DELETE SEGMENT 2 FROM TABLE DataRetentionTable")
sql("DELETE FROM TABLE DataRetentionTable WHERE SEGMENTS EQUAL 2 ")
sql(
"LOAD DATA LOCAL INPATH '" + resource + "dataretention1.csv' INTO TABLE DataRetentionTable " +
"OPTIONS('DELIMITER' = ',')")
Expand All @@ -177,7 +177,7 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {
test("RetentionTest4_DeleteByInvalidLoadId") {
try {
// delete segment with no id
sql("DELETE SEGMENT FROM TABLE DataRetentionTable")
sql("DELETE FROM TABLE DataRetentionTable WHERE SEGMENTS EQUAL")
assert(false)
} catch {
case e: MalformedCarbonCommandException =>
Expand All @@ -203,8 +203,8 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {
checkAnswer(
sql("select count(*) from cArbon_TaBlE_1"), Seq(Row(20)))

sql("delete segments from table carbon_TABLE_1 " +
"where starttime before '2099-07-28 11:00:00'")
sql("delete from table carbon_TABLE_1 " +
"where segments starttime before '2099-07-28 11:00:00'")

checkAnswer(
sql("select count(*) from caRbon_TabLe_1"), Seq(Row(0)))
Expand All @@ -214,7 +214,7 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {

try {
sql(
"DELETE SEGMENTS FROM TABLE DataRetentionTable where STARTTIME before" +
"DELETE FROM TABLE DataRetentionTable where SEGMENTS STARTTIME before" +
" 'abcd-01-01 00:00:00'")
assert(false)
} catch {
Expand All @@ -225,7 +225,7 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {

try {
sql(
"DELETE SEGMENTS FROM TABLE DataRetentionTable where STARTTIME before" +
"DELETE FROM TABLE DataRetentionTable where SEGMENTS STARTTIME before" +
" '2099:01:01 00:00:00'")
assert(false)
} catch {
Expand All @@ -240,7 +240,7 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {
),
Seq(Row("ind", 9))
)
sql("DELETE SEGMENTS FROM TABLE DataRetentionTable where STARTTIME before '2099-01-01'")
sql("DELETE FROM TABLE DataRetentionTable where SEGMENTS STARTTIME before '2099-01-01'")
checkAnswer(
sql("SELECT country, count(salary) AS amount FROM DataRetentionTable WHERE country" +
" IN ('china','ind','aus','eng') GROUP BY country"), Seq())
Expand Down Expand Up @@ -290,7 +290,7 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {
carbonCleanFilesLock.lockWithRetries()
// delete segment 0 it should fail
try {
sql("DELETE SEGMENT 0 FROM TABLE retentionlock")
sql("DELETE FROM TABLE retentionlock WHERE SEGMENTS EQUAL 0 ")
throw new MalformedCarbonCommandException("Invalid")
} catch {
case me: MalformedCarbonCommandException =>
Expand All @@ -301,7 +301,7 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {

// it should fail
try {
sql("DELETE SEGMENTS FROM TABLE retentionlock where STARTTIME before " +
sql("DELETE FROM TABLE retentionlock where SEGMENTS STARTTIME before " +
"'2099-01-01 00:00:00.0'")
throw new MalformedCarbonCommandException("Invalid")
} catch {
Expand All @@ -325,10 +325,10 @@ class DataRetentionTestCase extends QueryTest with BeforeAndAfterAll {
carbonCleanFilesLock.unlock()
carbonDeleteSegmentLock.unlock()

sql("DELETE SEGMENT 0 FROM TABLE retentionlock")
sql("DELETE FROM TABLE retentionlock WHERE SEGMENTS EQUAL 0 ")
//load and delete should execute parallely
carbonMetadataLock.lockWithRetries()
sql("DELETE SEGMENT 1 FROM TABLE retentionlock")
sql("DELETE FROM TABLE retentionlock WHERE SEGMENTS EQUAL 1 ")
carbonMetadataLock.unlock()
}
}

0 comments on commit 0f45d51

Please sign in to comment.