-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search bar for components + connection first step
- Loading branch information
Showing
51 changed files
with
1,071 additions
and
330 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
122 changes: 122 additions & 0 deletions
122
...mphi/packages/pipeline-components-core/src/components/inputs/databases/SnowflakeInput.tsx
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,122 @@ | ||
|
||
import { snowflakeIcon } from '../../../icons'; | ||
import { BaseCoreComponent } from '../../BaseCoreComponent'; | ||
|
||
export class SnowflakeInput extends BaseCoreComponent { | ||
constructor() { | ||
const defaultConfig = { dbOptions: { schema: "public", tableName: "" } }; | ||
const form = { | ||
fields: [ | ||
{ | ||
type: "input", | ||
label: "Account", | ||
id: "dbOptions.account", | ||
placeholder: "Enter Account", | ||
connection: "Snowflake", | ||
advanced: true | ||
}, | ||
{ | ||
type: "input", | ||
label: "Database Name", | ||
id: "dbOptions.databaseName", | ||
connection: "Snowflake", | ||
placeholder: "Enter database name", | ||
}, | ||
{ | ||
type: "input", | ||
label: "Username", | ||
id: "dbOptions.username", | ||
placeholder: "Enter username", | ||
connection: "Snowflake", | ||
advanced: true | ||
}, | ||
{ | ||
type: "input", | ||
label: "Password", | ||
id: "dbOptions.password", | ||
placeholder: "Enter password", | ||
connection: "Snowflake", | ||
inputType: "password", | ||
advanced: true | ||
}, | ||
{ | ||
type: "input", | ||
label: "Warehouse", | ||
id: "dbOptions.warehouse", | ||
placeholder: "Enter warehouse name", | ||
advanced: true | ||
}, | ||
{ | ||
type: "input", | ||
label: "Schema", | ||
id: "dbOptions.schema", | ||
placeholder: "Enter schema name", | ||
advanced: true | ||
}, | ||
{ | ||
type: "input", | ||
label: "Table Name", | ||
id: "dbOptions.tableName", | ||
placeholder: "Enter table name", | ||
}, | ||
{ | ||
type: "codeTextarea", | ||
label: "SQL Query", | ||
height: '50px', | ||
mode: "sql", | ||
placeholder: 'SELECT * FROM table_name', | ||
id: "dbOptions.sqlQuery", | ||
tooltip: 'Optional. By default the SQL query is: SELECT * FROM table_name_provided. If specified, the SQL Query is used.', | ||
advanced: true | ||
} | ||
], | ||
}; | ||
|
||
super("Snowflake Input", "snowflakeInput", "pandas_df_input", [], "inputs.Databases", snowflakeIcon, defaultConfig, form); | ||
} | ||
|
||
public provideDependencies({ config }): string[] { | ||
let deps: string[] = []; | ||
deps.push('snowflake-sqlalchemy'); | ||
return deps; | ||
} | ||
|
||
public provideImports({ config }): string[] { | ||
return ["import pandas as pd", "import sqlalchemy", "import urllib.parse", "from snowflake.sqlalchemy import URL"]; | ||
} | ||
|
||
public generateComponentCode({ config, outputName }): string { | ||
const uniqueEngineName = `${outputName}_Engine`; // Unique engine name based on the outputName | ||
const tableReference = (config.dbOptions.schema && config.dbOptions.schema.toLowerCase() !== 'public') | ||
? `${config.dbOptions.schema}.${config.dbOptions.tableName}` | ||
: config.dbOptions.tableName; | ||
|
||
const sqlQuery = config.dbOptions.sqlQuery && config.dbOptions.sqlQuery.trim() | ||
? config.dbOptions.sqlQuery | ||
: `SELECT * FROM ${tableReference}`; | ||
|
||
const code = ` | ||
# Connect to the Snowflake database | ||
${uniqueEngineName} = sqlalchemy.create_engine(URL( | ||
account = '${config.dbOptions.account}', | ||
user = '${config.dbOptions.username}', | ||
password = urllib.parse.quote("${config.dbOptions.password}"), | ||
database = '${config.dbOptions.database}', | ||
schema = '${config.dbOptions.schema}', | ||
warehouse = '${config.dbOptions.warehouse}' | ||
)) | ||
# Execute SQL statement | ||
try: | ||
with ${uniqueEngineName}.connect() as conn: | ||
${outputName} = pd.read_sql( | ||
"""${sqlQuery}""", | ||
con=conn.connection | ||
).convert_dtypes() | ||
finally: | ||
${uniqueEngineName}.dispose() | ||
`; | ||
return code; | ||
} | ||
|
||
} |
Oops, something went wrong.
606131b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#50 #48 #14