Skip to content

Commit

Permalink
duplicated code
Browse files Browse the repository at this point in the history
Signed-off-by: zyl891229 <zyl891229@hotmail.com>
  • Loading branch information
zyl891229 committed Feb 20, 2025
1 parent 5e29f69 commit f0b54d2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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.connector.paimon;

import com.starrocks.catalog.Column;
import com.starrocks.catalog.PaimonView;
import com.starrocks.catalog.Type;
import com.starrocks.connector.ColumnTypeConverter;
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.DataType;
import org.apache.paimon.view.View;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import static com.starrocks.connector.ConnectorTableId.CONNECTOR_ID_GENERATOR;

public class PaimonApiConverter {

@NotNull
static List<Column> toFullSchemas(List<DataField> fields) {
List<Column> columns = new ArrayList<>(fields.size());
for (DataField field : fields) {
String fieldName = field.name();
DataType type = field.type();
Type fieldType = ColumnTypeConverter.fromPaimonType(type);
Column column = new Column(fieldName, fieldType, true, field.description());
columns.add(column);
}
return columns;
}

@NotNull
static PaimonView getPaimonView(String catalogName, String dbName, String viewName, View paimonNativeView) {
List<DataField> fields = paimonNativeView.rowType().getFields();
List<Column> fullSchema = toFullSchemas(fields);
String comment = "";
if (paimonNativeView.comment().isPresent()) {
comment = paimonNativeView.comment().get();
}
PaimonView view = new PaimonView(CONNECTOR_ID_GENERATOR.getNextId().asInt(), catalogName, dbName, viewName,
fullSchema, paimonNativeView.query(), catalogName, dbName, "");
view.setComment(comment);
return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import com.starrocks.catalog.PaimonView;
import com.starrocks.catalog.PartitionKey;
import com.starrocks.catalog.Table;
import com.starrocks.catalog.Type;
import com.starrocks.common.DdlException;
import com.starrocks.common.ErrorCode;
import com.starrocks.common.ErrorReport;
import com.starrocks.connector.ColumnTypeConverter;
import com.starrocks.connector.ConnectorMetadatRequestContext;
import com.starrocks.connector.ConnectorMetadata;
import com.starrocks.connector.ConnectorProperties;
Expand Down Expand Up @@ -72,6 +70,7 @@
import org.apache.paimon.utils.DateTimeUtils;
import org.apache.paimon.view.View;
import org.apache.paimon.view.ViewImpl;
import org.jetbrains.annotations.NotNull;

Check failure on line 73 in fe/fe-core/src/main/java/com/starrocks/connector/paimon/PaimonMetadata.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Unused import - org.jetbrains.annotations.NotNull. Raw Output: /github/workspace/./fe/fe-core/src/main/java/com/starrocks/connector/paimon/PaimonMetadata.java:73:8: error: Unused import - org.jetbrains.annotations.NotNull. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -82,6 +81,8 @@

import static com.starrocks.connector.ColumnTypeConverter.toPaimonDataType;
import static com.starrocks.connector.ConnectorTableId.CONNECTOR_ID_GENERATOR;
import static com.starrocks.connector.paimon.PaimonApiConverter.getPaimonView;
import static com.starrocks.connector.paimon.PaimonApiConverter.toFullSchemas;

public class PaimonMetadata implements ConnectorMetadata {
private static final Logger LOG = LogManager.getLogger(PaimonMetadata.class);
Expand Down Expand Up @@ -288,14 +289,7 @@ public Table getTable(String dbName, String tblName) {
return getView(dbName, tblName);
}
List<DataField> fields = paimonNativeTable.rowType().getFields();
ArrayList<Column> fullSchema = new ArrayList<>(fields.size());
for (DataField field : fields) {
String fieldName = field.name();
DataType type = field.type();
Type fieldType = ColumnTypeConverter.fromPaimonType(type);
Column column = new Column(fieldName, fieldType, true, field.description());
fullSchema.add(column);
}
List<Column> fullSchema = toFullSchemas(fields);
long createTime = this.getTableCreateTime(dbName, tblName);
String comment = "";
if (paimonNativeTable.comment().isPresent()) {
Expand All @@ -319,27 +313,11 @@ public Table getView(String dbName, String viewName) {
LOG.error("Paimon view {}.{} does not exist.", dbName, viewName, e);
return null;
}
List<DataField> fields = paimonNativeView.rowType().getFields();
List<Column> columns = new ArrayList<>(fields.size());
for (DataField field : fields) {
String fieldName = field.name();
DataType type = field.type();
Type fieldType = ColumnTypeConverter.fromPaimonType(type);
Column column = new Column(fieldName, fieldType, true, field.description());
columns.add(column);
}
String comment = "";
if (paimonNativeView.comment().isPresent()) {
comment = paimonNativeView.comment().get();
}
PaimonView view = new PaimonView(CONNECTOR_ID_GENERATOR.getNextId().asInt(), catalogName, dbName, viewName,
columns, paimonNativeView.query(), catalogName, dbName, "");
view.setComment(comment);
PaimonView view = getPaimonView(this.catalogName, dbName, viewName, paimonNativeView);
tables.put(identifier, view);
return view;
}


@Override
public boolean tableExists(String dbName, String tableName) {
try {
Expand Down

0 comments on commit f0b54d2

Please sign in to comment.