Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 package test.org.apache.spark.sql.connector;
0019 
0020 import java.util.OptionalLong;
0021 
0022 import org.apache.spark.sql.connector.TestingV2Source;
0023 import org.apache.spark.sql.connector.catalog.Table;
0024 import org.apache.spark.sql.connector.read.InputPartition;
0025 import org.apache.spark.sql.connector.read.ScanBuilder;
0026 import org.apache.spark.sql.connector.read.Statistics;
0027 import org.apache.spark.sql.connector.read.SupportsReportStatistics;
0028 import org.apache.spark.sql.util.CaseInsensitiveStringMap;
0029 
0030 public class JavaReportStatisticsDataSource implements TestingV2Source {
0031   class MyScanBuilder extends JavaSimpleScanBuilder implements SupportsReportStatistics {
0032     @Override
0033     public Statistics estimateStatistics() {
0034       return new Statistics() {
0035         @Override
0036         public OptionalLong sizeInBytes() {
0037           return OptionalLong.of(80);
0038         }
0039 
0040         @Override
0041         public OptionalLong numRows() {
0042           return OptionalLong.of(10);
0043         }
0044       };
0045     }
0046 
0047     @Override
0048     public InputPartition[] planInputPartitions() {
0049       InputPartition[] partitions = new InputPartition[2];
0050       partitions[0] = new JavaRangeInputPartition(0, 5);
0051       partitions[1] = new JavaRangeInputPartition(5, 10);
0052       return partitions;
0053     }
0054   }
0055 
0056   @Override
0057   public Table getTable(CaseInsensitiveStringMap options) {
0058     return new JavaSimpleBatchTable() {
0059       @Override
0060       public ScanBuilder newScanBuilder(CaseInsensitiveStringMap options) {
0061         return new MyScanBuilder();
0062       }
0063     };
0064   }
0065 }