forked from apache/paimon
-
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.
- Loading branch information
Showing
6 changed files
with
250 additions
and
19 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...k/paimon-spark-3.3/src/main/scala/org/apache/spark/sql/connector/catalog/ViewCatalog.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,26 @@ | ||
/* | ||
* 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.spark.sql.connector.catalog; | ||
|
||
/** | ||
* Dummy placeholder to resolve compatibility issue of CatalogMaterializedTable(introduced in flink | ||
* 1.20). | ||
*/ | ||
public interface ViewCatalog { | ||
} |
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
92 changes: 92 additions & 0 deletions
92
paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkView.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,92 @@ | ||
/* | ||
* 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.paimon.spark; | ||
|
||
import org.apache.paimon.types.DataField; | ||
|
||
import org.apache.spark.sql.connector.catalog.View; | ||
import org.apache.spark.sql.types.StructType; | ||
|
||
import java.util.Map; | ||
|
||
/** Spark {@link View} for paimon. */ | ||
public class SparkView implements View { | ||
|
||
public static final String QUERY_COLUMN_NAMES = "spark.query-column-names"; | ||
|
||
private final String catalogName; | ||
|
||
private final org.apache.paimon.view.View paimonView; | ||
|
||
public SparkView(String catalogName, org.apache.paimon.view.View paimonView) { | ||
this.paimonView = paimonView; | ||
this.catalogName = catalogName; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return paimonView.fullName(); | ||
} | ||
|
||
@Override | ||
public String query() { | ||
return paimonView.query(); | ||
} | ||
|
||
@Override | ||
public String currentCatalog() { | ||
return catalogName; | ||
} | ||
|
||
@Override | ||
public String[] currentNamespace() { | ||
return new String[] {paimonView.fullName().split("\\.")[0]}; | ||
} | ||
|
||
@Override | ||
public StructType schema() { | ||
return SparkTypeUtils.fromPaimonRowType(paimonView.rowType()); | ||
} | ||
|
||
@Override | ||
public String[] queryColumnNames() { | ||
return paimonView.options().containsKey(QUERY_COLUMN_NAMES) | ||
? paimonView.options().get(QUERY_COLUMN_NAMES).split(",") | ||
: new String[0]; | ||
} | ||
|
||
@Override | ||
public String[] columnAliases() { | ||
return paimonView.rowType().getFields().stream() | ||
.map(DataField::name) | ||
.toArray(String[]::new); | ||
} | ||
|
||
@Override | ||
public String[] columnComments() { | ||
return paimonView.rowType().getFields().stream() | ||
.map(DataField::description) | ||
.toArray(String[]::new); | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return paimonView.options(); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkViewTest.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,65 @@ | ||
package org.apache.paimon.spark; | ||
|
||
import org.apache.paimon.fs.Path; | ||
import org.apache.paimon.hive.TestHiveMetastore; | ||
import org.apache.spark.sql.SparkSession; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SparkViewTest { | ||
private static TestHiveMetastore testHiveMetastore; | ||
|
||
private static final int PORT = 9087; | ||
|
||
@BeforeAll | ||
public static void startMetastore() { | ||
testHiveMetastore = new TestHiveMetastore(); | ||
testHiveMetastore.start(PORT); | ||
} | ||
|
||
@AfterAll | ||
public static void closeMetastore() throws Exception { | ||
testHiveMetastore.stop(); | ||
} | ||
|
||
// @Test | ||
// public void testView(@TempDir java.nio.file.Path tempDir) { | ||
// // firstly, we use hive metastore to create table, and check the result. | ||
// Path warehousePath = new Path("file:" + tempDir.toString()); | ||
// SparkSession spark = | ||
// SparkSession.builder() | ||
// .config("spark.sql.warehouse.dir", warehousePath.toString()) | ||
// // with case-sensitive false | ||
// .config("spark.sql.caseSensitive", "false") | ||
// // with hive metastore | ||
// .config("spark.sql.catalogImplementation", "hive") | ||
// .config( | ||
// "spark.sql.catalog.spark_catalog", | ||
// SparkCatalog.class.getName()) | ||
// .master("local[2]") | ||
// .getOrCreate(); | ||
// | ||
// spark.sql("CREATE DATABASE IF NOT EXISTS my_db1"); | ||
// spark.sql("USE my_db1"); | ||
// spark.sql( | ||
// "CREATE TABLE IF NOT EXISTS t2 (a INT, Bb INT, c STRING) USING paimon TBLPROPERTIES" | ||
// + " ('file.format'='avro')"); | ||
// | ||
// spark.sql("CREATE DATABASE IF NOT EXISTS my_db1"); | ||
// spark.sql("USE spark_catalog.my_db1"); | ||
// spark.sql( | ||
// "CREATE TABLE db_pt (a INT, b INT, c STRING) USING paimon TBLPROPERTIES" | ||
// + " ('file.format'='avro')"); | ||
// spark.sql("INSERT INTO db_pt VALUES (1, 2, '3'), (4, 5, '6')"); | ||
// spark.sql("CREATE VIEW spark_view as select a , b from db_pt"); | ||
// spark.sql("show views").collectAsList().forEach(System.out::println); | ||
// spark.sql("select * from spark_view").collectAsList().forEach(System.out::println); | ||
// | ||
// | ||
// spark.close(); | ||
// } | ||
} |
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