Skip to content

Instantly share code, notes, and snippets.

@izeigerman
Last active January 29, 2021 19:04
Show Gist options
  • Select an option

  • Save izeigerman/c1c16508c52f306a7aadc4589bd69a5b to your computer and use it in GitHub Desktop.

Select an option

Save izeigerman/c1c16508c52f306a7aadc4589bd69a5b to your computer and use it in GitHub Desktop.
import org.apache.spark.sql.SparkSession
trait DataSource[D, P] {
def read(parameters: P)(implicit spark: SparkSession): AnnotatedDataFrame[D]
}
object DataSource {
def apply[D]: Helper[D] = new Helper[D]
// Helper used to improve the type inference and make the reading API cleaner.
final class Helper[D] {
def read[P](parameters: P)(implicit S: DataSource[D, P], spark: SparkSession) =
S.read(parameters)
def read(implicit S: DataSource[D, Unit], spark: SparkSession) =
S.read(())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment