|
13 | 13 | */ |
14 | 14 | package org.apache.spark.sql.catalyst.parser.extensions |
15 | 15 |
|
| 16 | +import org.antlr.v4.runtime.ParserRuleContext |
16 | 17 | import org.apache.spark.sql.catalyst.analysis.{UnresolvedIdentifier, UnresolvedRelation} |
17 | | -import org.apache.spark.sql.catalyst.parser.ParserInterface |
18 | | -import org.apache.spark.sql.catalyst.plans.logical.{AddColumnsBackfill, AddIndex, LanceDropIndex, LanceNamedArgument, LogicalPlan, Optimize, SetUnenforcedPrimaryKey, ShowIndexes, UpdateColumnsBackfill, Vacuum} |
| 18 | +import org.apache.spark.sql.catalyst.parser.{ParseException, ParserInterface} |
| 19 | +import org.apache.spark.sql.catalyst.plans.logical.{AddColumnsBackfill, AddIndex, LanceCreateBranch, LanceDropBranch, LanceDropIndex, LanceNamedArgument, LanceShowBranches, LogicalPlan, Optimize, SetUnenforcedPrimaryKey, ShowIndexes, UpdateColumnsBackfill, Vacuum} |
19 | 20 | import org.lance.spark.utils.{FieldPathUtils, ParserUtils} |
20 | 21 |
|
21 | 22 | import scala.collection.JavaConverters._ |
@@ -115,6 +116,71 @@ class LanceSqlExtensionsAstBuilder(delegate: ParserInterface) |
115 | 116 | LanceDropIndex(table, indexName) |
116 | 117 | } |
117 | 118 |
|
| 119 | + override def visitCreateBranchRefMain(ctx: LanceSqlExtensionsParser.CreateBranchRefMainContext) |
| 120 | + : LanceCreateBranch = { |
| 121 | + val table = UnresolvedIdentifier(visitMultipartIdentifier(ctx.multipartIdentifier())) |
| 122 | + val branchName = cleanIdentifier(ctx.branchName.getText) |
| 123 | + val ifNotExists = ctx.EXISTS() != null |
| 124 | + if (ctx.refMainVersion == null) |
| 125 | + LanceCreateBranch(table, branchName, org.lance.Ref.ofMain(), ifNotExists) |
| 126 | + else LanceCreateBranch( |
| 127 | + table, |
| 128 | + branchName, |
| 129 | + org.lance.Ref.ofMain(_parseVersion(ctx, ctx.refMainVersion.getText)), |
| 130 | + ifNotExists) |
| 131 | + } |
| 132 | + |
| 133 | + override def visitCreateBranchRefBranch( |
| 134 | + ctx: LanceSqlExtensionsParser.CreateBranchRefBranchContext): LanceCreateBranch = { |
| 135 | + val table = UnresolvedIdentifier(visitMultipartIdentifier(ctx.multipartIdentifier())) |
| 136 | + val branchName = cleanIdentifier(ctx.branchName.getText) |
| 137 | + val refBranchName = cleanIdentifier(ctx.refBranchName.getText) |
| 138 | + val ifNotExists = ctx.EXISTS() != null |
| 139 | + if (ctx.refBranchVersion == null) |
| 140 | + LanceCreateBranch(table, branchName, org.lance.Ref.ofBranch(refBranchName), ifNotExists) |
| 141 | + else LanceCreateBranch( |
| 142 | + table, |
| 143 | + branchName, |
| 144 | + org.lance.Ref.ofBranch(refBranchName, _parseVersion(ctx, ctx.refBranchVersion.getText)), |
| 145 | + ifNotExists) |
| 146 | + } |
| 147 | + |
| 148 | + private def _parseVersion(ctx: ParserRuleContext, value: String): Long = { |
| 149 | + try { |
| 150 | + java.lang.Long.valueOf(value) |
| 151 | + } catch { |
| 152 | + case _: NumberFormatException => |
| 153 | + throw new ParseException( |
| 154 | + errorClass = "INVALID_TYPED_LITERAL", |
| 155 | + messageParameters = Map( |
| 156 | + "valueType" -> "LONG", |
| 157 | + "value" -> value), |
| 158 | + ctx) |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + override def visitCreateBranchRefTag(ctx: LanceSqlExtensionsParser.CreateBranchRefTagContext) |
| 163 | + : LanceCreateBranch = { |
| 164 | + val table = UnresolvedIdentifier(visitMultipartIdentifier(ctx.multipartIdentifier())) |
| 165 | + val branchName = cleanIdentifier(ctx.branchName.getText) |
| 166 | + val refTagName = cleanIdentifier(ctx.refTagName.getText) |
| 167 | + val ifNotExists = ctx.EXISTS() != null |
| 168 | + LanceCreateBranch(table, branchName, org.lance.Ref.ofTag(refTagName), ifNotExists) |
| 169 | + } |
| 170 | + |
| 171 | + override def visitDropBranch(ctx: LanceSqlExtensionsParser.DropBranchContext): LanceDropBranch = { |
| 172 | + val table = UnresolvedIdentifier(visitMultipartIdentifier(ctx.multipartIdentifier())) |
| 173 | + val branchName = cleanIdentifier(ctx.branchName.getText) |
| 174 | + val ifExists = ctx.EXISTS() != null |
| 175 | + LanceDropBranch(table, branchName, ifExists) |
| 176 | + } |
| 177 | + |
| 178 | + override def visitShowBranches(ctx: LanceSqlExtensionsParser.ShowBranchesContext) |
| 179 | + : LanceShowBranches = { |
| 180 | + val table = UnresolvedIdentifier(visitMultipartIdentifier(ctx.multipartIdentifier())) |
| 181 | + LanceShowBranches(table) |
| 182 | + } |
| 183 | + |
118 | 184 | override def visitSetUnenforcedPrimaryKey( |
119 | 185 | ctx: LanceSqlExtensionsParser.SetUnenforcedPrimaryKeyContext): SetUnenforcedPrimaryKey = { |
120 | 186 | val table = UnresolvedIdentifier(visitMultipartIdentifier(ctx.multipartIdentifier())) |
|
0 commit comments