forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add stream feature view in the Web UI (feast-dev#3257)
* add stream feature view to ui Signed-off-by: hao-affirm <[email protected]> * update source Signed-off-by: hao-affirm <[email protected]> * update example Signed-off-by: hao-affirm <[email protected]> * add registry Signed-off-by: hao-affirm <[email protected]> * fix lint Signed-off-by: hao-affirm <[email protected]> * fix bug Signed-off-by: hao-affirm <[email protected]> * add batch source Signed-off-by: hao-affirm <[email protected]> * fix warning Signed-off-by: hao-affirm <[email protected]> Signed-off-by: hao-affirm <[email protected]>
- Loading branch information
1 parent
532d8a1
commit 1f70b3a
Showing
16 changed files
with
625 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,24 @@ | |
"name": "zipcode", | ||
"timestampField": "event_timestamp", | ||
"type": "BATCH_FILE" | ||
}, | ||
{ | ||
"batchSource": { | ||
"fileOptions": { | ||
"uri": "data/zipcode_table.parquet" | ||
}, | ||
"name": "user_stats", | ||
"timestampField": "timestamp", | ||
"type": "BATCH_FILE" | ||
}, | ||
"dataSourceClassType": "feast.data_source.KafkaSource", | ||
"description": "The Kafka stream example", | ||
"kafkaOptions": {"messageFormat": {"jsonFormat": {"schemaJson": "id string, timestamp timestamp"}}, | ||
"watermarkDelayThreshold": "300s"}, | ||
"name": "driver_stats_stream", | ||
"owner": "[email protected]", | ||
"timestampField": "timestamp", | ||
"type": "STREAM_KAFKA" | ||
} | ||
], | ||
"entities": [ | ||
|
@@ -630,5 +648,59 @@ | |
} | ||
} | ||
], | ||
"streamFeatureViews": [ | ||
{ | ||
"meta": { | ||
"createdTimestamp": "2022-05-11T19:27:03.171556Z", | ||
"lastUpdatedTimestamp": "2022-05-11T19:27:03.171556Z" | ||
}, | ||
"spec": { | ||
"batchSource": { | ||
"createdTimestampColumn": "created_timestamp", | ||
"dataSourceClassType": "feast.infra.offline_stores.file_source.FileSource", | ||
"fileOptions": { | ||
"uri": "data/zipcode_table.parquet" | ||
}, | ||
"name": "zipcode", | ||
"timestampField": "event_timestamp", | ||
"type": "BATCH_FILE" | ||
}, | ||
"features": [ | ||
{ | ||
"name": "conv_percentage", | ||
"valueType": "FLOAT" | ||
}, | ||
{ | ||
"name": "acc_percentage", | ||
"valueType": "FLOAT" | ||
} | ||
], | ||
"name": "transaction_stream_example", | ||
"streamSource": { | ||
"batchSource": { | ||
"fileOptions": { | ||
"uri": "data/zipcode_table.parquet" | ||
}, | ||
"name": "user_stats", | ||
"timestampField": "timestamp", | ||
"type": "BATCH_FILE" | ||
}, | ||
"dataSourceClassType": "feast.data_source.KafkaSource", | ||
"description": "The Kafka stream example", | ||
"kafkaOptions": {"messageFormat": {"jsonFormat": {"schemaJson": "id string, timestamp timestamp"}}, | ||
"watermarkDelayThreshold": "300s"}, | ||
"name": "driver_stats_stream", | ||
"owner": "[email protected]", | ||
"timestampField": "timestamp", | ||
"type": "STREAM_KAFKA" | ||
}, | ||
"ttl": "86400s", | ||
"userDefinedFunction": { | ||
"body": "@stream_feature_view(\n sources=[driver_stats_stream_source],\n mode=\"spark\",\n schema=[\n Field(name=\"conv_percentage\", dtype=Float32),\n Field(name=\"acc_percentage\", dtype=Float32),\n ],\n timestamp_field=\"event_timestamp\",\n online=True,\n source=driver_stats_stream_source,\n tags={},\n)\ndef driver_hourly_stats_stream(df: DataFrame) -> DataFrame:\n from pyspark.sql.functions import col\n return (\n df.withColumn(\"conv_percentage\", col(\"conv_rate\") * 100.0)\n .withColumn(\"acc_percentage\", col(\"acc_rate\") * 100.0)\n .drop(\"conv_rate\", \"acc_rate\")\n )\n", | ||
"name": "driver_hourly_stats_stream" | ||
} | ||
} | ||
} | ||
], | ||
"project": "credit_scoring_aws" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from "react"; | ||
|
||
import { | ||
// Feature View Custom Tabs will get these props | ||
StreamFeatureViewCustomTabProps, | ||
} from "../types"; | ||
|
||
import { | ||
EuiLoadingContent, | ||
EuiEmptyPrompt, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiCode, | ||
EuiSpacer, | ||
} from "@elastic/eui"; | ||
|
||
// Separating out the query is not required, | ||
// but encouraged for code readability | ||
import useDemoQuery from "./useDemoQuery"; | ||
|
||
const DemoCustomTab = ({ | ||
id, | ||
feastObjectQuery, | ||
}: StreamFeatureViewCustomTabProps) => { | ||
// Use React Query to fetch data | ||
// that is custom to this tab. | ||
// See: https://react-query.tanstack.com/guides/queries | ||
const { isLoading, isError, isSuccess, data } = useDemoQuery({ | ||
featureView: id, | ||
}); | ||
|
||
if (isLoading) { | ||
// Handle Loading State | ||
// https://elastic.github.io/eui/#/display/loading | ||
return <EuiLoadingContent lines={3} />; | ||
} | ||
|
||
if (isError) { | ||
// Handle Data Fetching Error | ||
// https://elastic.github.io/eui/#/display/empty-prompt | ||
return ( | ||
<EuiEmptyPrompt | ||
iconType="alert" | ||
color="danger" | ||
title={<h2>Unable to load your demo page</h2>} | ||
body={ | ||
<p> | ||
There was an error loading the Dashboard application. Contact your | ||
administrator for help. | ||
</p> | ||
} | ||
/> | ||
); | ||
} | ||
|
||
// Feast UI uses the Elastic UI component system. | ||
// <EuiFlexGroup> and <EuiFlexItem> are particularly | ||
// useful for layouts. | ||
return ( | ||
<React.Fragment> | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={1}> | ||
<p>Hello World. The following is fetched data.</p> | ||
<EuiSpacer /> | ||
{isSuccess && data && ( | ||
<EuiCode> | ||
<pre>{JSON.stringify(data, null, 2)}</pre> | ||
</EuiCode> | ||
)} | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={2}> | ||
<p>... and this is data from Feast UI’s own query.</p> | ||
<EuiSpacer /> | ||
{feastObjectQuery.isSuccess && feastObjectQuery.data && ( | ||
<EuiCode> | ||
<pre>{JSON.stringify(feastObjectQuery.data, null, 2)}</pre> | ||
</EuiCode> | ||
)} | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export default DemoCustomTab; |
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,44 @@ | ||
import { useQuery } from "react-query"; | ||
import { z } from "zod"; | ||
|
||
// Use Zod to check the shape of the | ||
// json object being loaded | ||
const demoSchema = z.object({ | ||
hello: z.string(), | ||
name: z.string().optional(), | ||
}); | ||
|
||
// Make the type of the object available | ||
type DemoDataType = z.infer<typeof demoSchema>; | ||
|
||
interface DemoQueryInterface { | ||
featureView: string | undefined; | ||
} | ||
|
||
const useDemoQuery = ({ featureView }: DemoQueryInterface) => { | ||
// React Query manages caching for you based on query keys | ||
// See: https://react-query.tanstack.com/guides/query-keys | ||
const queryKey = `demo-tab-namespace:${featureView}`; | ||
|
||
// Pass the type to useQuery | ||
// so that components consuming the | ||
// result gets nice type hints | ||
// on the other side. | ||
return useQuery<DemoDataType>( | ||
queryKey, | ||
() => { | ||
// Customizing the URL based on your needs | ||
const url = `/demo-custom-tabs/demo.json`; | ||
|
||
return fetch(url) | ||
.then((res) => res.json()) | ||
.then((data) => demoSchema.parse(data)); // Use zod to parse results | ||
}, | ||
{ | ||
enabled: !!featureView, // Only start the query when the variable is not undefined | ||
} | ||
); | ||
}; | ||
|
||
export default useDemoQuery; | ||
export type { DemoDataType }; |
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
Oops, something went wrong.