Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Nov 11, 2024
1 parent 370eaf2 commit 8d8deba
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 2 deletions.
65 changes: 65 additions & 0 deletions docs/content/concepts/table-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,71 @@ CREATE TABLE my_parquet_table (

{{< /tabs >}}

## Object Table

Object Table provides metadata indexes for unstructured data objects in the specified Object Storage storage directory.
Object tables allow users to analyze unstructured data in Object Storage:

1. Use Python API to manipulate these unstructured data, such as converting images to PDF format.
2. Model functions can also be used to perform inference, and then the results of these operations can be concatenated
with other structured data in the Catalog.

The object table is managed by Catalog and can also have access permissions and the ability to manage blood relations.

{{< tabs "object-table" >}}

{{< tab "Flink-SQL" >}}

```sql
-- Create Object Table

CREATE TABLE `my_object_table` WITH (
'type' = 'object-table',
'object-location' = 'oss://my_bucket/my_location'
);

-- Refresh Object Table

CALL sys.refresh_object_table('mydb.my_object_table');

-- Query Object Table

SELECT * FROM `my_object_table`;

-- Query Object Table with Time Travel

SELECT * FROM `my_object_table` /*+ OPTIONS('scan.snapshot-id' = '1') */;
```

{{< /tab >}}

{{< tab "Spark-SQL" >}}

```sql
-- Create Object Table

CREATE TABLE `my_object_table` TBLPROPERTIES (
'type' = 'object-table',
'object-location' = 'oss://my_bucket/my_location'
);

-- Refresh Object Table

CALL sys.refresh_object_table('mydb.my_object_table');

-- Query Object Table

SELECT * FROM `my_object_table`;

-- Query Object Table with Time Travel

SELECT * FROM `my_object_table` VERSION AS OF 1;
```

{{< /tab >}}

{{< /tabs >}}

## Materialized Table

Materialized Table aimed at simplifying both batch and stream data pipelines, providing a consistent development
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import static org.apache.paimon.CoreOptions.PATH;
import static org.apache.paimon.utils.Preconditions.checkArgument;
import static org.apache.paimon.utils.Preconditions.checkNotNull;

/** Factory to create {@link FileStoreTable}. */
public class FileStoreTableFactory {
Expand Down Expand Up @@ -129,10 +130,12 @@ public static FileStoreTable createWithoutFallbackBranch(
table = table.copy(dynamicOptions.toMap());
CoreOptions options = table.coreOptions();
if (options.type() == TableType.OBJECT_TABLE) {
String objectLocation = options.objectLocation();
checkNotNull(objectLocation, "Object location should not be null for object table.");
table =
ObjectTable.builder()
.underlyingTable(table)
.objectLocation(options.objectLocation())
.objectLocation(objectLocation)
.build();
}
return table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public TableWriteImpl<?> newWrite(String commitUser, ManifestCacheFilter manifes

@Override
public TableCommitImpl newCommit(String commitUser) {
throw new UnsupportedOperationException("Object table does not support Write.");
throw new UnsupportedOperationException("Object table does not support Commit.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.paimon.spark.procedure.MigrateTableProcedure;
import org.apache.paimon.spark.procedure.Procedure;
import org.apache.paimon.spark.procedure.ProcedureBuilder;
import org.apache.paimon.spark.procedure.RefreshObjectTableProcedure;
import org.apache.paimon.spark.procedure.RemoveOrphanFilesProcedure;
import org.apache.paimon.spark.procedure.RenameTagProcedure;
import org.apache.paimon.spark.procedure.RepairProcedure;
Expand Down Expand Up @@ -87,6 +88,7 @@ private static Map<String, Supplier<ProcedureBuilder>> initProcedureBuilders() {
procedureBuilders.put("reset_consumer", ResetConsumerProcedure::builder);
procedureBuilders.put("mark_partition_done", MarkPartitionDoneProcedure::builder);
procedureBuilders.put("compact_manifest", CompactManifestProcedure::builder);
procedureBuilders.put("refresh_object_table", RefreshObjectTableProcedure::builder);
return procedureBuilders.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.procedure;

import org.apache.paimon.table.object.ObjectTable;

import org.apache.spark.sql.catalyst.InternalRow;
import org.apache.spark.sql.connector.catalog.Identifier;
import org.apache.spark.sql.connector.catalog.TableCatalog;
import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.Metadata;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;

import static org.apache.spark.sql.types.DataTypes.StringType;

/** Spark procedure to refresh Object Table. */
public class RefreshObjectTableProcedure extends BaseProcedure {

private static final ProcedureParameter[] PARAMETERS =
new ProcedureParameter[] {ProcedureParameter.required("table", StringType)};

private static final StructType OUTPUT_TYPE =
new StructType(
new StructField[] {
new StructField("file_number", DataTypes.LongType, false, Metadata.empty())
});

protected RefreshObjectTableProcedure(TableCatalog tableCatalog) {
super(tableCatalog);
}

@Override
public ProcedureParameter[] parameters() {
return PARAMETERS;
}

@Override
public StructType outputType() {
return OUTPUT_TYPE;
}

@Override
public InternalRow[] call(InternalRow args) {
Identifier tableIdent = toIdentifier(args.getString(0), PARAMETERS[0].name());
return modifyPaimonTable(
tableIdent,
table -> {
ObjectTable objectTable = (ObjectTable) table;
long fileNumber = objectTable.refresh();
InternalRow outputRow = newInternalRow(fileNumber);
return new InternalRow[] {outputRow};
});
}

public static ProcedureBuilder builder() {
return new Builder<RefreshObjectTableProcedure>() {
@Override
public RefreshObjectTableProcedure doBuild() {
return new RefreshObjectTableProcedure(tableCatalog());
}
};
}

@Override
public String description() {
return "RefreshObjectTableProcedure";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.sql

import org.apache.paimon.fs.Path
import org.apache.paimon.fs.local.LocalFileIO
import org.apache.paimon.spark.PaimonSparkTestBase

import org.apache.spark.sql.Row

class ObjectTableTest extends PaimonSparkTestBase {

test(s"Paimon object table") {
val objectLocation = new Path(tempDBDir + "/object-location")
val fileIO = LocalFileIO.create

spark.sql(s"""
|CREATE TABLE T TBLPROPERTIES (
| 'type' = 'object-table',
| 'object-location' = '$objectLocation'
|)
|""".stripMargin)

// add new file
fileIO.overwriteFileUtf8(new Path(objectLocation, "f0"), "1,2,3")
spark.sql("CALL sys.refresh_object_table('test.T')")
checkAnswer(
spark.sql("SELECT name, length FROM T"),
Row("f0", 5L) :: Nil
)

// add new file
fileIO.overwriteFileUtf8(new Path(objectLocation, "f1"), "4,5,6")
spark.sql("CALL sys.refresh_object_table('test.T')")
checkAnswer(
spark.sql("SELECT name, length FROM T"),
Row("f0", 5L) :: Row("f1", 5L) :: Nil
)

// time travel
checkAnswer(
spark.sql("SELECT name, length FROM T VERSION AS OF 1"),
Row("f0", 5L) :: Nil
)
}
}

0 comments on commit 8d8deba

Please sign in to comment.