Class SparkEngine
java.lang.Object
com.logicalclocks.hsfs.engine.EngineBase
com.logicalclocks.hsfs.spark.engine.SparkEngine
-
Field Summary
Fields inherited from class com.logicalclocks.hsfs.engine.EngineBase
LOGGER, storageConnectorApi -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.spark.sql.Dataset<org.apache.spark.sql.Row>castColumnType(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, List<TrainingDatasetFeature> features) voidconstructCheckpointPath(FeatureGroupBase featureGroup, String queryName, String queryPrefix) org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>convertToDefaultDataframe(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset) <S> ScreateEmptyDataFrame(S datasetGeneric) voiddeleteOnlineDataframe(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, Map<String, String> writeOptions) Produces an online delete tombstone for every row in the dataset.org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>encodeComplexFeatures(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset) Encodes all complex type features to binary using their avro type as schema.static SparkEnginegetKafkaConfig(FeatureGroupBase featureGroup, Map<String, String> writeOptions) getReadOptions(Map<String, String> providedOptions, DataFormat dataFormat) getWriteOptions(Map<String, String> providedOptions, DataFormat dataFormat) protected StringmakeQueryName(String queryName, FeatureGroupBase featureGroup) org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>objectToDataset(Object obj) parseFeatureGroupSchema(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, TimeTravelFormat timeTravelFormat) profile(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> df) profile(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> df, boolean correlation, boolean histogram) profile(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> df, List<String> restrictToColumns, Boolean correlation, Boolean histogram) profile(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> df, List<String> restrictToColumns, Boolean correlation, Boolean histogram, Boolean exactUniqueness) profile(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> df, List<String> restrictToColumns, Boolean correlation, Boolean histogram, Boolean exactUniqueness, Boolean kll, Integer histogramBins) org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>read(StorageConnector storageConnector, String dataFormat, Map<String, String> readOptions, String location) org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>readStream(StorageConnector storageConnector, String dataFormat, String messageFormat, String schema, Map<String, String> options, boolean includeMetadata) voidregisterHudiTemporaryTable(FeatureGroupAlias featureGroupAlias, Map<String, String> readOptions) org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>registerOnDemandTemporaryTable(ExternalFeatureGroup onDemandFeatureGroup, String alias) org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>sanitizeFeatureNames(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset) static voidsetInstance(SparkEngine sparkEngine) voidsetupConnectorHadoopConf(StorageConnector storageConnector) static Stringorg.apache.spark.sql.Dataset<org.apache.spark.sql.Row>[]splitDataset(TrainingDataset trainingDataset, Query query, Map<String, String> readOptions) static List<org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>>splitLabels(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, List<String> labels) org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>voidstreamToHudiTable(StreamFeatureGroup streamFeatureGroup, Map<String, String> writeOptions) voidorg.apache.spark.sql.Dataset<org.apache.spark.sql.Row>[]write(TrainingDataset trainingDataset, Query query, Map<String, String> queryReadOptions, Map<String, String> writeOptions, org.apache.spark.sql.SaveMode saveMode) Setup Spark to write the data on the File System.voidwriteEmptyDataframe(FeatureGroupBase featureGroup) voidwriteOfflineDataframe(FeatureGroupBase featureGroup, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, HudiOperationType operation, Map<String, String> writeOptions, Integer validationId) voidwriteOnlineDataframe(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, Map<String, String> writeOptions) Writes feature group dataframe to kafka for online-fs ingestion.voidwriteOnlineDataframe(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, Map<String, String> writeOptions, Storage storage) Writes feature group dataframe to kafka for online-fs ingestion.<S> org.apache.spark.sql.streaming.StreamingQuerywriteStreamDataframe(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, String queryName, String outputMode, boolean awaitTermination, Long timeout, String checkpointLocation, Map<String, String> writeOptions)
-
Method Details
-
getInstance
-
setInstance
-
validateSparkConfiguration
- Throws:
FeatureStoreException
-
getTrustStorePath
-
getKeyStorePath
-
getCertKey
-
sql
-
registerOnDemandTemporaryTable
public org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> registerOnDemandTemporaryTable(ExternalFeatureGroup onDemandFeatureGroup, String alias) throws FeatureStoreException, IOException - Throws:
FeatureStoreExceptionIOException
-
splitLabels
-
registerHudiTemporaryTable
public void registerHudiTemporaryTable(FeatureGroupAlias featureGroupAlias, Map<String, String> readOptions) throws FeatureStoreException- Throws:
FeatureStoreException
-
write
public org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>[] write(TrainingDataset trainingDataset, Query query, Map<String, String> queryReadOptions, Map<String, throws FeatureStoreException, IOExceptionString> writeOptions, org.apache.spark.sql.SaveMode saveMode) Setup Spark to write the data on the File System.- Parameters:
trainingDataset- Training Dataset metadata objectquery- Query ObjectqueryReadOptions- Additional read options as key-value pairs, defaults to empty MapwriteOptions- Additional write options as key-value pairs, defaults to empty MapsaveMode- org.apache.spark.sql.saveMode: Append, Overwrite, ErrorIfExists, Ignore- Returns:
- Spark dataframe
- Throws:
FeatureStoreException- If Client is not connected to HopsworksIOException- Generic IO exception.
-
splitDataset
public org.apache.spark.sql.Dataset<org.apache.spark.sql.Row>[] splitDataset(TrainingDataset trainingDataset, Query query, Map<String, String> readOptions) throws FeatureStoreException, IOException- Throws:
FeatureStoreExceptionIOException
-
getWriteOptions
-
getReadOptions
-
read
public org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> read(StorageConnector storageConnector, String dataFormat, Map<String, String> readOptions, String location) throws FeatureStoreException, IOException- Throws:
FeatureStoreExceptionIOException
-
writeOnlineDataframe
public void writeOnlineDataframe(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, Map<String, String> writeOptions) throws FeatureStoreException, IOExceptionWrites feature group dataframe to kafka for online-fs ingestion.- Parameters:
featureGroupBase-dataset-writeOptions- options map; supported keys under"online_ingestion_options.*"include"online_ingestion_options.disable_online_ingestion_count"(boolean string), and"online_ingestion_options.upsert_if_newer"(boolean string, only updates a row if the new value is newer than the existing one)- Throws:
FeatureStoreExceptionIOException
-
writeOnlineDataframe
public void writeOnlineDataframe(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, Map<String, String> writeOptions, Storage storage) throws FeatureStoreException, IOExceptionWrites feature group dataframe to kafka for online-fs ingestion.- Parameters:
featureGroupBase-dataset-writeOptions- options map; seewriteOnlineDataframe(FeatureGroupBase, Dataset, Map)storage- which consumer of the topic is meant to ingest these records:Storage.ONLINEwhen the offline leg is written straight to the table (or does not exist), so that the offline materialization job does not write the same rows a second time; null when the topic is the only source of both stores and both consumers read the records- Throws:
FeatureStoreExceptionIOException
-
writeStreamDataframe
public <S> org.apache.spark.sql.streaming.StreamingQuery writeStreamDataframe(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, String queryName, String outputMode, boolean awaitTermination, Long timeout, String checkpointLocation, Map<String, String> writeOptions) throws FeatureStoreException, IOException, org.apache.spark.sql.streaming.StreamingQueryException, TimeoutException- Throws:
FeatureStoreExceptionIOExceptionorg.apache.spark.sql.streaming.StreamingQueryExceptionTimeoutException
-
deleteOnlineDataframe
public void deleteOnlineDataframe(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, Map<String, String> writeOptions) throws FeatureStoreException, IOExceptionProduces an online delete tombstone for every row in the dataset.Each message carries the row encoded against the feature group Avro schema plus an
operation: deleteheader; OnlineFS deletes the row by primary key and ignores the values. The dataset needs to carry only the primary key: non-key columns are filled with null so the Avro schema serializes.The deletes are tracked by the same online ingestion record as an insert, and reported under its
DELETEDstatus, so the removed rows are counted apart from written ones.The tombstone is marked
Storage.ONLINE: removeRows applies the offline delete straight to the table, so the offline materialization job has to skip it rather than re-insert the key the delete removed.- Parameters:
featureGroupBase- the online-enabled feature groupdataset- the rows to deletewriteOptions- kafka write options- Throws:
FeatureStoreExceptionIOException
-
encodeComplexFeatures
public org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> encodeComplexFeatures(FeatureGroupBase featureGroupBase, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset) throws FeatureStoreException, IOException Encodes all complex type features to binary using their avro type as schema.- Parameters:
featureGroupBase- FeatureGroupBase Feature Group hsfs metadata objectdataset- Spark DataFrame or RDD.- Returns:
- Spark DataFrame.
- Throws:
FeatureStoreException- If Client is not connected to HopsworksIOException- Generic IO exception.
-
writeEmptyDataframe
public void writeEmptyDataframe(FeatureGroupBase featureGroup) throws IOException, FeatureStoreException, ParseException -
writeOfflineDataframe
public void writeOfflineDataframe(FeatureGroupBase featureGroup, org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, HudiOperationType operation, Map<String, String> writeOptions, Integer validationId) throws IOException, FeatureStoreException, ParseException -
profile
-
profile
-
profile
-
profile
-
profile
public String profile(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> df, boolean correlation, boolean histogram) -
profile
-
setupConnectorHadoopConf
public void setupConnectorHadoopConf(StorageConnector storageConnector) throws IOException, FeatureStoreException - Throws:
IOExceptionFeatureStoreException
-
sparkPath
-
streamToHudiTable
public void streamToHudiTable(StreamFeatureGroup streamFeatureGroup, Map<String, String> writeOptions) throws Exception- Throws:
Exception
-
parseFeatureGroupSchema
public List<Feature> parseFeatureGroupSchema(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, TimeTravelFormat timeTravelFormat) throws FeatureStoreException - Throws:
FeatureStoreException
-
sanitizeFeatureNames
public org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> sanitizeFeatureNames(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset) -
convertToDefaultDataframe
public org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> convertToDefaultDataframe(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset) -
castColumnType
public org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> castColumnType(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataset, List<TrainingDatasetFeature> features) throws FeatureStoreException - Throws:
FeatureStoreException
-
addFile
- Specified by:
addFilein classEngineBase- Throws:
FeatureStoreException
-
getKafkaConfig
public Map<String,String> getKafkaConfig(FeatureGroupBase featureGroup, Map<String, String> writeOptions) throws FeatureStoreException, IOException- Specified by:
getKafkaConfigin classEngineBase- Throws:
FeatureStoreExceptionIOException
-
readStream
public org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> readStream(StorageConnector storageConnector, String dataFormat, String messageFormat, String schema, Map<String, String> options, boolean includeMetadata) throws FeatureStoreException, IOException- Throws:
FeatureStoreExceptionIOException
-
objectToDataset
-
createEmptyDataFrame
public <S> S createEmptyDataFrame(S datasetGeneric) -
constructCheckpointPath
public String constructCheckpointPath(FeatureGroupBase featureGroup, String queryName, String queryPrefix) throws FeatureStoreException, IOException - Throws:
FeatureStoreExceptionIOException
-
makeQueryName
-
closeSparkSession
public void closeSparkSession()
-