Skip to content

Commit

Permalink
Make TableFormat extensible| mapper convert
Browse files Browse the repository at this point in the history
  • Loading branch information
baiyangtx committed Sep 9, 2024
1 parent ecb5690 commit 5e83dc6
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.amoro.server.persistence.converter;

import org.apache.amoro.TableFormat;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@MappedTypes(TableFormat.class)
@MappedJdbcTypes(JdbcType.VARCHAR)
public class TableFormatConverter implements TypeHandler<TableFormat> {

@Override
public void setParameter(PreparedStatement ps, int i, TableFormat parameter, JdbcType jdbcType)
throws SQLException {
if (parameter == null) {
ps.setString(i, "");
} else {
ps.setString(i, parameter.name());
}
}

@Override
public TableFormat getResult(ResultSet rs, String columnName) throws SQLException {
String res = rs.getString(columnName);
if (res == null) {
return null;
}
return TableFormat.valueOf(res);
}

@Override
public TableFormat getResult(ResultSet rs, int columnIndex) throws SQLException {
String res = rs.getString(columnIndex);
if (res == null) {
return null;
}
return TableFormat.valueOf(res);
}

@Override
public TableFormat getResult(CallableStatement cs, int columnIndex) throws SQLException {
String res = cs.getString(columnIndex);
if (res == null) {
return null;
}
return TableFormat.valueOf(res);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.amoro.server.persistence.converter.Long2TsConverter;
import org.apache.amoro.server.persistence.converter.Map2StringConverter;
import org.apache.amoro.server.persistence.converter.MapLong2StringConverter;
import org.apache.amoro.server.persistence.converter.TableFormatConverter;
import org.apache.amoro.server.table.TableMetadata;
import org.apache.amoro.server.table.TableRuntime;
import org.apache.amoro.server.table.TableRuntimeMeta;
Expand Down Expand Up @@ -77,7 +78,10 @@ Integer decTableCount(
@Result(property = "tableIdentifier.tableName", column = "table_name"),
@Result(property = "tableIdentifier.database", column = "db_name"),
@Result(property = "tableIdentifier.catalog", column = "catalog_name"),
@Result(property = "tableIdentifier.format", column = "format"),
@Result(
property = "tableIdentifier.format",
column = "format",
typeHandler = TableFormatConverter.class),
@Result(property = "primaryKey", column = "primary_key"),
@Result(property = "tableLocation", column = "table_location"),
@Result(property = "baseLocation", column = "base_location"),
Expand Down Expand Up @@ -112,7 +116,10 @@ Integer decTableCount(
@Result(property = "tableIdentifier.catalog", column = "catalog_name"),
@Result(property = "tableIdentifier.database", column = "db_name"),
@Result(property = "tableIdentifier.tableName", column = "table_name"),
@Result(property = "tableIdentifier.format", column = "format"),
@Result(
property = "tableIdentifier.format",
column = "format",
typeHandler = TableFormatConverter.class),
@Result(property = "primaryKey", column = "primary_key"),
@Result(property = "tableLocation", column = "table_location"),
@Result(property = "baseLocation", column = "base_location"),
Expand Down Expand Up @@ -182,7 +189,10 @@ int commitTableChange(
@Result(property = "tableIdentifier.catalog", column = "catalog_name"),
@Result(property = "tableIdentifier.database", column = "db_name"),
@Result(property = "tableIdentifier.tableName", column = "table_name"),
@Result(property = "tableIdentifier.format", column = "format"),
@Result(
property = "tableIdentifier.format",
column = "format",
typeHandler = TableFormatConverter.class),
@Result(property = "primaryKey", column = "primary_key"),
@Result(property = "tableLocation", column = "table_location"),
@Result(property = "baseLocation", column = "base_location"),
Expand Down Expand Up @@ -217,7 +227,10 @@ int commitTableChange(
@Result(property = "tableIdentifier.catalog", column = "catalog_name"),
@Result(property = "tableIdentifier.database", column = "db_name"),
@Result(property = "tableIdentifier.tableName", column = "table_name"),
@Result(property = "tableIdentifier.format", column = "format"),
@Result(
property = "tableIdentifier.format",
column = "format",
typeHandler = TableFormatConverter.class),
@Result(property = "primaryKey", column = "primary_key"),
@Result(property = "tableLocation", column = "table_location"),
@Result(property = "baseLocation", column = "base_location"),
Expand Down Expand Up @@ -267,7 +280,7 @@ Integer deleteTableIdByName(
@Result(property = "tableName", column = "table_name"),
@Result(property = "database", column = "db_name"),
@Result(property = "catalog", column = "catalog_name"),
@Result(property = "format", column = "format"),
@Result(property = "format", column = "format", typeHandler = TableFormatConverter.class)
})
ServerTableIdentifier selectTableIdentifier(
@Param("catalogName") String catalogName,
Expand All @@ -282,7 +295,7 @@ ServerTableIdentifier selectTableIdentifier(
@Result(property = "catalog", column = "catalog_name"),
@Result(property = "database", column = "db_name"),
@Result(property = "tableName", column = "table_name"),
@Result(property = "format", column = "format")
@Result(property = "format", column = "format", typeHandler = TableFormatConverter.class)
})
List<ServerTableIdentifier> selectTableIdentifiersByDb(
@Param("catalogName") String catalogName, @Param("databaseName") String databaseName);
Expand All @@ -295,7 +308,7 @@ List<ServerTableIdentifier> selectTableIdentifiersByDb(
@Result(property = "catalog", column = "catalog_name"),
@Result(property = "database", column = "db_name"),
@Result(property = "tableName", column = "table_name"),
@Result(property = "format", column = "format")
@Result(property = "format", column = "format", typeHandler = TableFormatConverter.class)
})
List<ServerTableIdentifier> selectTableIdentifiersByCatalog(
@Param("catalogName") String catalogName);
Expand All @@ -306,7 +319,7 @@ List<ServerTableIdentifier> selectTableIdentifiersByCatalog(
@Result(property = "catalog", column = "catalog_name"),
@Result(property = "database", column = "db_name"),
@Result(property = "tableName", column = "table_name"),
@Result(property = "format", column = "format")
@Result(property = "format", column = "format", typeHandler = TableFormatConverter.class)
})
List<ServerTableIdentifier> selectAllTableIdentifiers();

Expand Down Expand Up @@ -380,7 +393,7 @@ List<ServerTableIdentifier> selectTableIdentifiersByCatalog(
@Result(property = "catalogName", column = "catalog_name"),
@Result(property = "dbName", column = "db_name"),
@Result(property = "tableName", column = "table_name"),
@Result(property = "format", column = "format"),
@Result(property = "format", column = "format", typeHandler = TableFormatConverter.class),
@Result(property = "currentSnapshotId", column = "current_snapshot_id"),
@Result(property = "currentChangeSnapshotId", column = "current_change_snapshotId"),
@Result(property = "lastOptimizedSnapshotId", column = "last_optimized_snapshotId"),
Expand Down

0 comments on commit 5e83dc6

Please sign in to comment.