-
Notifications
You must be signed in to change notification settings - Fork 999
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support report partitioning to eliminate shuffle exchange
- Loading branch information
1 parent
39ca57d
commit 3fbeda5
Showing
14 changed files
with
573 additions
and
24 deletions.
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
paimon-core/src/main/java/org/apache/paimon/table/BucketSpec.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 @@ | ||
/* | ||
* 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.table; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Bucket spec holds all bucket information, we can do plan optimization during table scan. | ||
* | ||
* <p>If the `bucketMode` is {@link BucketMode#HASH_DYNAMIC}, then `numBucket` is -1; | ||
* | ||
* @since 0.9 | ||
*/ | ||
public class BucketSpec { | ||
|
||
private BucketMode bucketMode; | ||
private List<String> bucketKeys; | ||
private int numBucket; | ||
|
||
public BucketSpec(BucketMode bucketMode, List<String> bucketKeys, int numBucket) { | ||
this.bucketMode = bucketMode; | ||
this.bucketKeys = bucketKeys; | ||
this.numBucket = numBucket; | ||
} | ||
|
||
public BucketMode getBucketMode() { | ||
return bucketMode; | ||
} | ||
|
||
public List<String> getBucketKeys() { | ||
return bucketKeys; | ||
} | ||
|
||
public int getNumBucket() { | ||
return numBucket; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BucketSpec{" | ||
+ "bucketMode=" | ||
+ bucketMode | ||
+ ", bucketKeys=" | ||
+ bucketKeys | ||
+ ", numBucket=" | ||
+ numBucket | ||
+ '}'; | ||
} | ||
} |
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
88 changes: 88 additions & 0 deletions
88
...spark/paimon-spark-3.5/src/main/java/org/apache/paimon/spark/catalog/PaimonFunctions.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,88 @@ | ||
/* | ||
* 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.catalog; | ||
|
||
import org.apache.spark.sql.connector.catalog.functions.BoundFunction; | ||
import org.apache.spark.sql.connector.catalog.functions.UnboundFunction; | ||
import org.apache.spark.sql.types.DataType; | ||
import org.apache.spark.sql.types.StructField; | ||
import org.apache.spark.sql.types.StructType; | ||
|
||
import static org.apache.paimon.utils.Preconditions.checkArgument; | ||
import static org.apache.spark.sql.types.DataTypes.IntegerType; | ||
|
||
/** | ||
* It should be only used for resolving, e.g., for {@link | ||
* org.apache.spark.sql.connector.read.SupportsReportPartitioning}. | ||
*/ | ||
public class PaimonFunctions { | ||
/** | ||
* For now, we only support report bucket partitioning for table scan. So the case `SELECT | ||
* bucket(10, col)` would fail since we do not implement {@link | ||
* org.apache.spark.sql.connector.catalog.functions.ScalarFunction} | ||
*/ | ||
public static class BucketFunction implements UnboundFunction { | ||
@Override | ||
public BoundFunction bind(StructType inputType) { | ||
if (inputType.size() != 2) { | ||
throw new UnsupportedOperationException( | ||
"Wrong number of inputs (expected numBuckets and value)"); | ||
} | ||
|
||
StructField numBucket = inputType.fields()[0]; | ||
StructField bucketField = inputType.fields()[1]; | ||
checkArgument( | ||
numBucket.dataType() == IntegerType, | ||
"bucket number field must be integer type"); | ||
|
||
return new BoundFunction() { | ||
@Override | ||
public DataType[] inputTypes() { | ||
return new DataType[] {IntegerType, bucketField.dataType()}; | ||
} | ||
|
||
@Override | ||
public DataType resultType() { | ||
return IntegerType; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "bucket"; | ||
} | ||
|
||
@Override | ||
public String canonicalName() { | ||
// We have to override this method to make it support canonical equivalent | ||
return "paimon.bucket(" + bucketField.dataType().catalogString() + ", int)"; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return name(); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "bucket"; | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...park/paimon-spark-3.5/src/main/java/org/apache/paimon/spark/catalog/SparkBaseCatalog.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,97 @@ | ||
/* | ||
* 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.catalog; | ||
|
||
import org.apache.paimon.catalog.Catalog; | ||
import org.apache.paimon.spark.SparkProcedures; | ||
import org.apache.paimon.spark.SparkSource; | ||
import org.apache.paimon.spark.analysis.NoSuchProcedureException; | ||
import org.apache.paimon.spark.procedure.Procedure; | ||
import org.apache.paimon.spark.procedure.ProcedureBuilder; | ||
|
||
import org.apache.paimon.shade.guava30.com.google.common.collect.ImmutableMap; | ||
|
||
import org.apache.spark.sql.catalyst.analysis.NoSuchFunctionException; | ||
import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException; | ||
import org.apache.spark.sql.connector.catalog.FunctionCatalog; | ||
import org.apache.spark.sql.connector.catalog.Identifier; | ||
import org.apache.spark.sql.connector.catalog.SupportsNamespaces; | ||
import org.apache.spark.sql.connector.catalog.TableCatalog; | ||
import org.apache.spark.sql.connector.catalog.functions.UnboundFunction; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
||
import scala.Option; | ||
|
||
/** Spark base catalog. */ | ||
public abstract class SparkBaseCatalog | ||
implements TableCatalog, | ||
FunctionCatalog, | ||
SupportsNamespaces, | ||
ProcedureCatalog, | ||
WithPaimonCatalog { | ||
|
||
protected String catalogName; | ||
|
||
@Override | ||
public String name() { | ||
return catalogName; | ||
} | ||
|
||
@Override | ||
public Procedure loadProcedure(Identifier identifier) throws NoSuchProcedureException { | ||
if (Catalog.SYSTEM_DATABASE_NAME.equals(identifier.namespace()[0])) { | ||
ProcedureBuilder builder = SparkProcedures.newBuilder(identifier.name()); | ||
if (builder != null) { | ||
return builder.withTableCatalog(this).build(); | ||
} | ||
} | ||
throw new NoSuchProcedureException(identifier); | ||
} | ||
|
||
public boolean usePaimon(String provider) { | ||
return provider == null || SparkSource.NAME().equalsIgnoreCase(provider); | ||
} | ||
|
||
// --------------------- Function Catalog Methods ---------------------------- | ||
private static final Map<String, UnboundFunction> FUNCTIONS = | ||
ImmutableMap.of("bucket", new PaimonFunctions.BucketFunction()); | ||
|
||
@Override | ||
public UnboundFunction loadFunction(Identifier ident) throws NoSuchFunctionException { | ||
UnboundFunction func = FUNCTIONS.get(ident.name()); | ||
if (func == null) { | ||
throw new NoSuchFunctionException( | ||
"Function " + ident + " is not a paimon function", Option.empty()); | ||
} | ||
return func; | ||
} | ||
|
||
@Override | ||
public Identifier[] listFunctions(String[] namespace) throws NoSuchNamespaceException { | ||
if (namespace.length != 0) { | ||
throw new NoSuchNamespaceException( | ||
"Namespace " + Arrays.toString(namespace) + " is not valid", Option.empty()); | ||
} | ||
return FUNCTIONS.keySet().stream() | ||
.map(name -> Identifier.of(namespace, name)) | ||
.toArray(Identifier[]::new); | ||
} | ||
} |
Oops, something went wrong.