-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java): support statistics row num for lance scan (#3304)
Support statistics row num for lance scan, and with this statistics the spark will choose the broadcast to join for a small table. But now the byte size of lance dataset is inferred by row number. It is not very precise. Maybe We should store the file size in meta as disscus in #3221.
- Loading branch information
1 parent
8fe7147
commit 8a23d50
Showing
7 changed files
with
141 additions
and
8 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
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
54 changes: 54 additions & 0 deletions
54
java/spark/src/main/java/com/lancedb/lance/spark/read/LanceStatistics.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,54 @@ | ||
/* | ||
* 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 | ||
* | ||
* 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 com.lancedb.lance.spark.read; | ||
|
||
import com.lancedb.lance.spark.LanceConfig; | ||
import com.lancedb.lance.spark.internal.LanceDatasetAdapter; | ||
import com.lancedb.lance.spark.utils.Optional; | ||
|
||
import org.apache.spark.sql.connector.read.Statistics; | ||
import org.apache.spark.sql.types.StructType; | ||
|
||
import java.util.OptionalLong; | ||
|
||
public class LanceStatistics implements Statistics { | ||
private final Optional<Long> rowNumber; | ||
private final Optional<StructType> schema; | ||
|
||
public LanceStatistics(LanceConfig config) { | ||
this.rowNumber = LanceDatasetAdapter.getDatasetRowCount(config); | ||
this.schema = LanceDatasetAdapter.getSchema(config); | ||
} | ||
|
||
@Override | ||
public OptionalLong sizeInBytes() { | ||
// TODO: Support quickly get the bytes on disk for the lance dataset | ||
// Now use schema to infer the byte size for simple | ||
if (rowNumber.isPresent()) { | ||
return OptionalLong.of(schema.get().defaultSize() * rowNumber.get()); | ||
} else { | ||
return OptionalLong.empty(); | ||
} | ||
} | ||
|
||
@Override | ||
public OptionalLong numRows() { | ||
if (rowNumber.isPresent()) { | ||
return OptionalLong.of(rowNumber.get()); | ||
} else { | ||
return OptionalLong.empty(); | ||
} | ||
} | ||
} |
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