Skip to content

Commit

Permalink
Make OptimizeSpatial outputLocation optional (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin authored May 3, 2022
1 parent 048b0f2 commit 551d74d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Azavea
* Copyright 2022 Azavea
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2022 Azavea
*
* 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.carto.analyticstoolbox.index.h3

import com.uber.h3core.H3CoreV3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.types.BinaryType

object OptimizeSpatial extends Serializable {

def apply(
sourceTable: String,
outputTable: String,
Expand Down Expand Up @@ -123,4 +122,12 @@ object OptimizeSpatial extends Serializable {

math.max(dfc.head.getLong(0) * 10 / 2, blockSizeDefault)
}

/** Optimization function defaults. */
val DEFAULT_OUTPUT_LOCATION: String = "/FileStore/tables/carto_default/"
val DEFAULT_GEOM_COLUMN: String = "geom"
val DEFAULT_ZOOM: Int = 8
val DEFAULT_BLOCK_SIZE: Long = 2097000
val DEFAULT_COMPRESSION: String = "lz4"
val DEFAULT_MAX_RECORDS_PER_FILE: Int = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,28 @@ import org.apache.spark.sql.SparkSession

package object spatial extends Serializable {
implicit class SparkSessionOps(val ssc: SparkSession) extends AnyVal {
import OptimizeSpatial._

def optimizeSpatial(
sourceTable: String,
outputTable: String,
outputLocation: String,
geomColumn: String = "geom",
zoom: Int = 8,
blockSizeDefault: Long = 2097000,
compression: String = "lz4",
maxRecordsPerFile: Int = 0
outputLocation: String = DEFAULT_OUTPUT_LOCATION,
geomColumn: String = DEFAULT_GEOM_COLUMN,
zoom: Int = DEFAULT_ZOOM,
blockSizeDefault: Long = DEFAULT_BLOCK_SIZE,
compression: String = DEFAULT_COMPRESSION,
maxRecordsPerFile: Int = DEFAULT_MAX_RECORDS_PER_FILE
): Unit = OptimizeSpatial(sourceTable, outputTable, outputLocation, geomColumn, zoom, blockSizeDefault, compression, maxRecordsPerFile)(ssc)

def optimizeSpatialManual(
sourceTable: String,
outputTable: String,
outputLocation: String,
geomColumn: String = "geom",
zoom: Int = 8,
blockSize: Long = 2097000,
compression: String = "lz4",
maxRecordsPerFile: Int = 0
outputLocation: String = DEFAULT_OUTPUT_LOCATION,
geomColumn: String = DEFAULT_GEOM_COLUMN,
zoom: Int = DEFAULT_ZOOM,
blockSize: Long = DEFAULT_BLOCK_SIZE,
compression: String = DEFAULT_COMPRESSION,
maxRecordsPerFile: Int = DEFAULT_MAX_RECORDS_PER_FILE
): Unit = OptimizeSpatial(sourceTable, outputTable, outputLocation, geomColumn, zoom, _ => blockSize, compression, maxRecordsPerFile)(ssc)
}
}

0 comments on commit 551d74d

Please sign in to comment.