forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: fphantam <[email protected]>
- Loading branch information
Showing
15 changed files
with
481 additions
and
5 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
fe/fe-core/src/main/java/org/apache/doris/catalog/external/LakeSoulExternalDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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.doris.catalog.external; | ||
|
||
import org.apache.doris.catalog.TableIf; | ||
import org.apache.doris.datasource.ExternalCatalog; | ||
import org.apache.doris.datasource.InitDatabaseLog; | ||
import org.apache.doris.datasource.lakesoul.LakeSoulExternalCatalog; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class LakeSoulExternalDatabase extends ExternalDatabase<LakeSoulExternalTable> { | ||
|
||
private static final Logger LOG = LogManager.getLogger(LakeSoulExternalDatabase.class); | ||
|
||
public LakeSoulExternalDatabase(ExternalCatalog extCatalog, long id, String name) { | ||
super(extCatalog, id, name, InitDatabaseLog.Type.LAKESOUL); | ||
} | ||
|
||
@Override | ||
protected LakeSoulExternalTable getExternalTable(String tableName, long tblId, ExternalCatalog catalog) { | ||
return new LakeSoulExternalTable(tblId, tableName, name, (LakeSoulExternalCatalog) catalog); | ||
} | ||
|
||
@Override | ||
public List<LakeSoulExternalTable> getTablesOnIdOrder() { | ||
return getTables().stream().sorted(Comparator.comparing(TableIf::getName)).collect(Collectors.toList()); | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
fe/fe-core/src/main/java/org/apache/doris/catalog/external/LakeSoulExternalTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// 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.doris.catalog.external; | ||
|
||
import com.dmetasoul.lakesoul.meta.dao.TableInfoDao; | ||
import com.dmetasoul.lakesoul.meta.entity.TableInfo; | ||
import com.google.common.collect.Lists; | ||
import org.apache.arrow.vector.types.pojo.Schema; | ||
import org.apache.doris.catalog.Column; | ||
import org.apache.doris.catalog.ScalarType; | ||
import org.apache.doris.catalog.Type; | ||
import org.apache.doris.datasource.lakesoul.LakeSoulExternalCatalog; | ||
import org.apache.doris.thrift.TLakeSoulTable; | ||
import org.apache.doris.thrift.TTableDescriptor; | ||
import org.apache.doris.thrift.TTableType; | ||
import org.apache.spark.sql.execution.arrow.ArrowUtils; | ||
import org.apache.spark.sql.types.DataType; | ||
import org.apache.spark.sql.types.DecimalType; | ||
import org.apache.spark.sql.types.StructField; | ||
import org.apache.spark.sql.types.StructType; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.spark.sql.types.DataTypes.BinaryType; | ||
import static org.apache.spark.sql.types.DataTypes.BooleanType; | ||
import static org.apache.spark.sql.types.DataTypes.ByteType; | ||
import static org.apache.spark.sql.types.DataTypes.DateType; | ||
import static org.apache.spark.sql.types.DataTypes.DoubleType; | ||
import static org.apache.spark.sql.types.DataTypes.IntegerType; | ||
import static org.apache.spark.sql.types.DataTypes.LongType; | ||
import static org.apache.spark.sql.types.DataTypes.StringType; | ||
import static org.apache.spark.sql.types.DataTypes.TimestampType; | ||
|
||
|
||
public class LakeSoulExternalTable extends ExternalTable { | ||
|
||
public static final int LAKESOUL_TIMESTAMP_SCALE_MS = 6; | ||
public LakeSoulExternalTable(long id, String name, String dbName, LakeSoulExternalCatalog catalog) { | ||
super(id, name, catalog, dbName, TableType.LAKESOUl_EXTERNAL_TABLE); | ||
} | ||
|
||
@Override | ||
public List<Column> initSchema() { | ||
String tableSchema = ((LakeSoulExternalCatalog) catalog).getLakeSoulTable(dbName, name).getTableSchema(); | ||
StructType schema = null; | ||
System.out.println(tableSchema); | ||
if (TableInfoDao.isArrowKindSchema(tableSchema)) { | ||
try { | ||
schema = ArrowUtils.fromArrowSchema(Schema.fromJSON(tableSchema)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} else { | ||
throw new RuntimeException("please upgrade lakesoul-common to latest version"); | ||
} | ||
List<Column> tmpSchema = Lists.newArrayListWithCapacity(schema.size()); | ||
for (StructField field : schema.fields()) { | ||
|
||
tmpSchema.add(new Column(field.name(), lakeSoulTypeToDorisType(field.dataType()), field.nullable())); | ||
} | ||
return tmpSchema; | ||
} | ||
|
||
private Type lakeSoulTypeToDorisType(DataType dt) { | ||
|
||
if (dt.equals(BooleanType)) { | ||
return Type.BOOLEAN; | ||
} else if (dt.equals(ByteType)) { | ||
return Type.TINYINT; | ||
} else if (dt.equals(Type.SMALLINT)) { | ||
return Type.SMALLINT; | ||
}else if (dt.equals(IntegerType)) { | ||
return Type.INT; | ||
} else if (dt.equals(LongType)) { | ||
return Type.BIGINT; | ||
} else if (dt.equals(DoubleType)) { | ||
return Type.DOUBLE; | ||
} else if (dt.equals(StringType) || dt.equals(BinaryType)) { | ||
return Type.STRING; | ||
} else if (dt instanceof DecimalType) { | ||
DecimalType decimalType = (DecimalType) dt; | ||
return ScalarType.createDecimalV3Type(decimalType.precision(), decimalType.scale()); | ||
} else if (dt.equals(DateType)) { | ||
return ScalarType.createDateV2Type(); | ||
} else if (dt.equals(TimestampType)) { | ||
return ScalarType.createDatetimeV2Type(LAKESOUL_TIMESTAMP_SCALE_MS); | ||
} else if (dt instanceof StructType) { | ||
ArrayList<org.apache.doris.catalog.StructField> fields = new ArrayList<>(); | ||
for (StructField structField : ((StructType) dt).fields()) { | ||
fields.add(new org.apache.doris.catalog.StructField(structField.name(), lakeSoulTypeToDorisType(structField.dataType()))); | ||
} | ||
return new org.apache.doris.catalog.StructType(fields); | ||
} | ||
throw new IllegalArgumentException("Cannot transform unknown type: " + dt); | ||
} | ||
|
||
@Override | ||
public TTableDescriptor toThrift() { | ||
List<Column> schema = getFullSchema(); | ||
TLakeSoulTable tLakeSoulTable = new TLakeSoulTable(dbName, name, new HashMap<>()); | ||
TTableDescriptor tTableDescriptor = new TTableDescriptor(getId(), TTableType.HIVE_TABLE, schema.size(), 0, | ||
getName(), dbName); | ||
tTableDescriptor.setLakesoulTable(tLakeSoulTable); | ||
return tTableDescriptor; | ||
|
||
} | ||
|
||
public TableInfo getLakeSoulTableInfo() { | ||
return ((LakeSoulExternalCatalog) catalog).getLakeSoulTable(dbName, name); | ||
} | ||
|
||
public String tablePath() { | ||
return ((LakeSoulExternalCatalog) catalog).getLakeSoulTable(dbName, name).getTablePath(); | ||
} | ||
|
||
public Map<String, String> getHadoopProperties() { | ||
return catalog.getCatalogProperty().getHadoopProperties(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ public enum Type { | |
MAX_COMPUTE, | ||
HUDI, | ||
PAIMON, | ||
LAKESOUL, | ||
TEST, | ||
UNKNOWN; | ||
} | ||
|
81 changes: 81 additions & 0 deletions
81
fe/fe-core/src/main/java/org/apache/doris/datasource/lakesoul/LakeSoulExternalCatalog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// 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.doris.datasource.lakesoul; | ||
|
||
import com.dmetasoul.lakesoul.meta.DBManager; | ||
import com.dmetasoul.lakesoul.meta.entity.TableInfo; | ||
import org.apache.doris.datasource.CatalogProperty; | ||
import org.apache.doris.datasource.ExternalCatalog; | ||
import org.apache.doris.datasource.InitCatalogLog; | ||
import org.apache.doris.datasource.SessionContext; | ||
import org.apache.doris.datasource.property.PropertyConverter; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class LakeSoulExternalCatalog extends ExternalCatalog { | ||
|
||
private static final Logger LOG = LogManager.getLogger(LakeSoulExternalCatalog.class); | ||
|
||
private final DBManager dbManager; | ||
|
||
public LakeSoulExternalCatalog(long catalogId, String name, String resource, Map<String, String> props, | ||
String comment) { | ||
super(catalogId, name, InitCatalogLog.Type.LAKESOUL, comment); | ||
props = PropertyConverter.convertToMetaProperties(props); | ||
dbManager = new DBManager(); | ||
catalogProperty = new CatalogProperty(resource, props); | ||
} | ||
@Override | ||
protected List<String> listDatabaseNames() { | ||
return dbManager.listNamespaces(); | ||
} | ||
|
||
@Override | ||
public List<String> listTableNames(SessionContext ctx, String dbName) { | ||
List<TableInfo> tifs = dbManager.getTableInfosByNamespace(getRealTableName(dbName)); | ||
List<String> tableNames = new ArrayList<>(100); | ||
for (TableInfo item : tifs) { | ||
// if (FlinkUtil.isTable(item)) { | ||
tableNames.add(item.getTableName()); | ||
// } | ||
} | ||
return tableNames; | ||
} | ||
|
||
@Override | ||
public boolean tableExist(SessionContext ctx, String dbName, String tblName) { | ||
TableInfo tableInfo = | ||
dbManager.getTableInfoByNameAndNamespace(getRealTableName(dbName), tblName); | ||
|
||
return null != tableInfo; | ||
} | ||
|
||
@Override | ||
protected void initLocalObjectsImpl() { | ||
|
||
} | ||
|
||
public TableInfo getLakeSoulTable(String dbName, String tblName) { | ||
makeSureInitialized(); | ||
return dbManager.getTableInfoByNameAndNamespace(dbName, tblName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.