diff --git a/start-db-calcite/src/main/java/org/apache/calcite/sql/ddl/SqlDropIndex.java b/start-db-calcite/src/main/java/org/apache/calcite/sql/ddl/SqlDropIndex.java new file mode 100644 index 00000000..e00139b4 --- /dev/null +++ b/start-db-calcite/src/main/java/org/apache/calcite/sql/ddl/SqlDropIndex.java @@ -0,0 +1,90 @@ +/* + * This file is inherited from Apache Calcite and modifed by ST-Lab under apache license. + * You can find the original code from + * + * https://github.com/apache/calcite + * + * 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.calcite.sql.ddl; + +import org.apache.calcite.sql.*; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.urbcomp.start.db.util.StringUtil; + +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.List; + +public class SqlDropIndex extends SqlDdl { + + private String indexName; + + /** + * 表名 + */ + private SqlIdentifier relation; + + /** + * 构造方法 + * + * @param operator 操作类型 + * @param pos 解析位置 + */ + public SqlDropIndex(SqlOperator operator, SqlParserPos pos) { + super(operator, pos); + } + + public SqlDropIndex(SqlParserPos pos, String indexName, SqlIdentifier relation) { + this(new SqlSpecialOperator("DROP INDEX", SqlKind.DROP_INDEX), pos); + this.indexName = StringUtil.dropQuota(indexName); + this.relation = relation; + } + + @Nonnull + @Override + public List getOperandList() { + return new ArrayList<>(); + } + + public String getIndexName() { + return indexName; + } + + public void setIndexName(String indexName) { + this.indexName = indexName; + } + + public SqlIdentifier getRelation() { + return relation; + } + + public void setRelation(SqlIdentifier relation) { + this.relation = relation; + } + + @Override + public String toString() { + return "SqlDropTableIndex{" + + "indexName='" + + indexName + + '\'' + + ", relation=" + + relation + + '}'; + } +} diff --git a/start-db-core/src/main/scala/org/urbcomp/start/db/executor/DropIndexExecutor.scala b/start-db-core/src/main/scala/org/urbcomp/start/db/executor/DropIndexExecutor.scala new file mode 100644 index 00000000..c6d3dafb --- /dev/null +++ b/start-db-core/src/main/scala/org/urbcomp/start/db/executor/DropIndexExecutor.scala @@ -0,0 +1,36 @@ +/* + * Copyright 2022 ST-Lab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +package org.urbcomp.start.db.executor + +import org.apache.calcite.sql.ddl.SqlDropIndex +import org.urbcomp.start.db.executor.utils.ExecutorUtil +import org.urbcomp.start.db.infra.{BaseExecutor, MetadataResult} +import org.urbcomp.start.db.metadata.MetadataAccessUtil +import org.urbcomp.start.db.util.SqlParam + +case class DropIndexExecutor(node: SqlDropIndex) extends BaseExecutor { + + override def execute[Int](): MetadataResult[Int] = { + val param = SqlParam.CACHE.get() + val targetTable = node.getRelation + val (userName, dbName, tableName) = ExecutorUtil.getUserNameDbNameAndTableName(targetTable) + // 判断该表是否已经存在 + val user = MetadataAccessUtil.getUser(userName) + val db = MetadataAccessUtil.getDatabase(user.getId, dbName) + val existedTable = MetadataAccessUtil.getTable(db.getId, tableName) + if (existedTable == null) { + throw new IllegalArgumentException("table doesn't exist " + tableName) + } + // 具体的删除索引逻辑 + + } +}