Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 drop index 内容 #325

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<SqlNode> 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
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
// 具体的删除索引逻辑

}
}