Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Commit 808faed

Browse files
committed
Basic Error handling when SQL program tables/viewnames change.
In this case we might not always be able connect all Connectors them in the config anymore.
1 parent 2ab91c3 commit 808faed

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

web-ui/src/pages/streaming/builder/index.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { useDebouncedCallback } from 'use-debounce'
2929
import { removePrefix } from 'src/utils'
3030
import { useReplacePlaceholder } from 'src/streaming/builder/hooks/useSqlPlaceholderClick'
3131
import { projectToProjectWithSchema } from 'src/types/program'
32-
import { useAddConnector } from 'src/streaming/builder/hooks/useAddIoNode'
32+
import { connectorConnects, useAddConnector } from 'src/streaming/builder/hooks/useAddIoNode'
3333
import MissingSchemaDialog from 'src/streaming/builder/NoSchemaDialog'
3434
import useStatusNotification from 'src/components/errors/useStatusNotification'
3535

@@ -107,7 +107,10 @@ export const PipelineWithProvider = (props: {
107107
setConfig(configQuery.data.config)
108108
setSaveState('isUpToDate')
109109

110-
console.log(configQuery.data.attached_connectors)
110+
const attachedConnectors = configQuery.data.attached_connectors
111+
let invalidConnections: AttachedConnector[] = []
112+
let validConnections: AttachedConnector[] = attachedConnectors
113+
console.log(attachedConnectors)
111114

112115
// We don't set saveState here because we don't want to override the
113116
// saveState (when we get the query result back). Otherwise it will cancel
@@ -123,14 +126,32 @@ export const PipelineWithProvider = (props: {
123126
}
124127

125128
const programWithSchema = projectToProjectWithSchema(foundProject)
129+
if (attachedConnectors) {
130+
invalidConnections = attachedConnectors.filter(attached_connector => {
131+
return !connectorConnects(attached_connector, programWithSchema.schema)
132+
})
133+
validConnections = attachedConnectors.filter(attached_connector => {
134+
return connectorConnects(attached_connector, programWithSchema.schema)
135+
})
136+
}
137+
126138
setProject(programWithSchema)
127139
replacePlaceholder(programWithSchema)
128140
}
129141
}
130142

131-
if (configQuery.data.attached_connectors) {
132-
const attachedConnectors = configQuery.data.attached_connectors
133-
attachedConnectors.forEach(attached_connector => {
143+
if (invalidConnections.length > 0) {
144+
pushMessage({
145+
key: new Date().getTime(),
146+
color: 'warning',
147+
message: `Could not attach ${
148+
invalidConnections.length
149+
} connector(s): No tables/views named ${invalidConnections.map(c => c.config).join(', ')} found.`
150+
})
151+
}
152+
153+
if (validConnections) {
154+
validConnections.forEach(attached_connector => {
134155
const connector = connectorQuery.data.find(
135156
connector => connector.connector_id === attached_connector.connector_id
136157
)
@@ -165,7 +186,8 @@ export const PipelineWithProvider = (props: {
165186
setProject,
166187
replacePlaceholder,
167188
addConnector,
168-
configId
189+
configId,
190+
pushMessage
169191
])
170192

171193
const debouncedSave = useDebouncedCallback(() => {
@@ -205,8 +227,6 @@ export const PipelineWithProvider = (props: {
205227
}
206228
)
207229
} else {
208-
console.log('update existing config')
209-
210230
// Update an existing config
211231
const connectors: Array<AttachedConnector> = getEdges().map(edge => {
212232
const source = getNode(edge.source)

web-ui/src/streaming/builder/hooks/useAddIoNode.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@ import { useCallback } from 'react'
44
import { NodeProps, useReactFlow, getConnectedEdges } from 'reactflow'
55
import { AttachedConnector, Direction } from 'src/types/manager'
66
import { ConnectorDescr } from 'src/types/manager/models/ConnectorDescr'
7+
import { Schema } from 'src/types/program'
78
import { randomString } from 'src/utils'
89

910
const HEIGHT_OFFSET = 120
1011

12+
// Checks if the connector can connect to a give schema
13+
export function connectorConnects(ac: AttachedConnector, schema: Schema): boolean {
14+
console.log('connectorConnects', ac, schema)
15+
if (ac.direction === Direction.INPUT) {
16+
return schema.inputs.some(table => table.name === ac.config)
17+
} else {
18+
return schema.outputs.some(view => view.name === ac.config)
19+
}
20+
}
21+
1122
export function useAddConnector() {
1223
const { setNodes, getNodes, getNode, addNodes, addEdges } = useReactFlow()
1324

0 commit comments

Comments
 (0)