Skip to content

Commit

Permalink
changes for mysql8 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
eshishki committed Feb 7, 2025
1 parent 72a602c commit 1ba8ad0
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ Long getRowCount(JdbcTableHandle table)
return handle.createQuery("" +
"SELECT TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES " +
"WHERE TABLE_SCHEMA = :schema AND TABLE_NAME = :table_name " +
"AND TABLE_TYPE = 'BASE TABLE' ")
"AND TABLE_TYPE = 'TABLE' ")
.bind("schema", remoteTableName.getCatalogName().orElse(null))
.bind("table_name", remoteTableName.getTableName())
.mapTo(Long.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String getComment() {

@Override
public String getMysqlType() {
return "BASE TABLE";
return "TABLE";
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions fe/fe-core/src/main/java/com/starrocks/catalog/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ public String getMysqlType() {
case SCHEMA:
return "SYSTEM VIEW";
default:
// external table also returns "BASE TABLE" for BI compatibility
return "BASE TABLE";
// external table also returns "TABLE" for BI compatibility
return "TABLE";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public class SystemId {

public static final long TEMP_TABLES_ID = 43L;

public static final long APPLICABLE_ROLES_ID = 44L;

public static final long SYS_DB_ID = 100L;

public static final long ROLE_EDGES_ID = 101L;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// Licensed 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
//
// https://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 com.starrocks.catalog.system.information;

import com.starrocks.catalog.ScalarType;
import com.starrocks.catalog.Table;
import com.starrocks.catalog.system.SystemId;
import com.starrocks.catalog.system.SystemTable;
import com.starrocks.thrift.TSchemaTableType;

import static com.starrocks.catalog.system.SystemTable.NAME_CHAR_LEN;
import static com.starrocks.catalog.system.SystemTable.builder;

public class ApplicableRolesSystemTable {
private static final String NAME = "applicable_roles";

public static SystemTable create(String catalogName) {
return new SystemTable(
catalogName,
SystemId.APPLICABLE_ROLES_ID,
NAME,
Table.TableType.SCHEMA,
builder()
.column("USER", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("HOST", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("GRANTEE", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("GRANTEE_HOST", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("ROLE_NAME", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("ROLE_HOST", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("IS_GRANTABLE", ScalarType.createVarchar(3))
.column("IS_DEFAULT", ScalarType.createVarchar(3))
.column("IS_MANDATORY", ScalarType.createVarchar(3))
.build(), TSchemaTableType.SCH_APPLICABLE_ROLES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public InfoSchemaDb(String catalogName) {

super.registerTableUnlocked(TablesSystemTable.create(catalogName));
super.registerTableUnlocked(PartitionsSystemTableSystemTable.create(catalogName));
super.registerTableUnlocked(ApplicableRolesSystemTable.create(catalogName));
super.registerTableUnlocked(TablePrivilegesSystemTable.create(catalogName));
super.registerTableUnlocked(ColumnPrivilegesSystemTable.create(catalogName));
super.registerTableUnlocked(ReferentialConstraintsSystemTable.create(catalogName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static SystemTable create(String catalogName) {
.column("PARTITION_NAME", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("SUBPARTITION_NAME", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("PARTITION_ORDINAL_POSITION", ScalarType.createType(PrimitiveType.BIGINT))
.column("SUBPARTITION_ORDINAL_POSITION", ScalarType.createType(PrimitiveType.BIGINT))
.column("PARTITION_METHOD", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("SUBPARTITION_METHOD", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("PARTITION_EXPRESSION", ScalarType.createVarchar(NAME_CHAR_LEN))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public static SystemTable create(String catalogName) {
.column("INDEX_TYPE", ScalarType.createVarchar(16))
.column("COMMENT", ScalarType.createVarchar(16))
.column("INDEX_COMMENT", ScalarType.createVarchar(1024))
.column("IS_VISIBLE", ScalarType.createVarchar(3))
.column("EXPRESSION", ScalarType.createVarchar(1024))
.build(), TSchemaTableType.SCH_STATISTICS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static SystemTable create(String catalogName) {
.column("TABLE_SCHEMA", ScalarType.createVarchar(64))
.column("TABLE_NAME", ScalarType.createVarchar(64))
.column("CONSTRAINT_TYPE", ScalarType.createVarchar(64))
.column("ENFORCED", ScalarType.createVarchar(3))
.build(), TSchemaTableType.SCH_TABLE_CONSTRAINTS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public class SessionVariable implements Serializable, Writable, Cloneable {
public static final String TX_ISOLATION = "tx_isolation";
public static final String TX_READ_ONLY = "tx_read_only";
public static final String TRANSACTION_ISOLATION = "transaction_isolation";
public static final String DEFAULT_STORAGE_ENGINE = "default_storage_engine";
public static final String DEFAULT_TMP_STORAGE_ENGINE = "default_tmp_storage_engine";
public static final String TRANSACTION_READ_ONLY = "transaction_read_only";
public static final String CHARACTER_SET_CLIENT = "character_set_client";
public static final String CHARACTER_SET_CONNNECTION = "character_set_connection";
Expand Down Expand Up @@ -1043,6 +1045,12 @@ public static MaterializedViewRewriteMode parse(String str) {
@VariableMgr.VarAttr(name = COLLATION_SERVER)
private String collationServer = "utf8_general_ci";

// this is used to compatible mysql 8
@VariableMgr.VarAttr(name = DEFAULT_STORAGE_ENGINE)
private String defaultStorageEngine = "InnoDB";
@VariableMgr.VarAttr(name = DEFAULT_TMP_STORAGE_ENGINE)
private String defaultTmpStorageEngine = "InnoDB";

// this is used to make c3p0 library happy
@VariableMgr.VarAttr(name = SQL_AUTO_IS_NULL)
private boolean sqlAutoIsNull = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.starrocks.catalog.Table;
import com.starrocks.catalog.Table.TableType;
import com.starrocks.cluster.ClusterNamespace;
import com.starrocks.common.CaseSensibility;
import com.starrocks.common.PatternMatcher;
import com.starrocks.common.proc.PartitionsProcDir;
import com.starrocks.common.util.concurrent.lock.LockType;
Expand Down Expand Up @@ -88,11 +87,11 @@ public class InformationSchemaDataSource {
private static AuthDbRequestResult getAuthDbRequestResult(TAuthInfo authInfo) throws TException {
List<String> authorizedDbs = Lists.newArrayList();
PatternMatcher matcher = null;
boolean caseSensitive = CaseSensibility.DATABASE.getCaseSensibility();
boolean caseSensitive = false;
if (authInfo.isSetPattern()) {
try {
matcher = PatternMatcher.createMysqlPattern(authInfo.getPattern(),
CaseSensibility.DATABASE.getCaseSensibility());
caseSensitive);
} catch (SemanticException e) {
throw new TException("Pattern is in bad format: " + authInfo.getPattern());
}
Expand Down
24 changes: 12 additions & 12 deletions fe/fe-core/src/test/java/com/starrocks/catalog/TableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ public void setUp() {

@Test
public void testGetMysqlType() {
Assert.assertEquals("BASE TABLE", new Table(TableType.OLAP).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.OLAP_EXTERNAL).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.CLOUD_NATIVE).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.OLAP).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.OLAP_EXTERNAL).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.CLOUD_NATIVE).getMysqlType());

Assert.assertEquals("BASE TABLE", new Table(TableType.MYSQL).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.BROKER).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.ELASTICSEARCH).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.HIVE).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.ICEBERG).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.HUDI).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.JDBC).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.DELTALAKE).getMysqlType());
Assert.assertEquals("BASE TABLE", new Table(TableType.FILE).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.MYSQL).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.BROKER).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.ELASTICSEARCH).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.HIVE).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.ICEBERG).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.HUDI).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.JDBC).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.DELTALAKE).getMysqlType());
Assert.assertEquals("TABLE", new Table(TableType.FILE).getMysqlType());

Assert.assertEquals("VIEW", new Table(TableType.INLINE_VIEW).getMysqlType());
Assert.assertEquals("VIEW", new Table(TableType.VIEW).getMysqlType());
Expand Down
2 changes: 2 additions & 0 deletions gensrc/thrift/Descriptors.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ enum TSchemaTableType {

SCH_CLUSTER_SNAPSHOTS,
SCH_CLUSTER_SNAPSHOT_JOBS,

SCH_APPLICABLE_ROLES,
}

enum THdfsCompression {
Expand Down

0 comments on commit 1ba8ad0

Please sign in to comment.