-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improvement: better sql completions #3930
Open
Light2Dark
wants to merge
8
commits into
marimo-team:main
Choose a base branch
from
Light2Dark:fix-sql-completions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
29e424a
use schema mappings instead of db
Light2Dark 4b41192
use common atom and properly qualify name for ai completion
Light2Dark dca32f8
add default db & schema
Light2Dark 25c26ab
modify completion source mapping
Light2Dark f6e0973
update sql completions and tests
Light2Dark 75eed35
add default schema, remove top level table
Light2Dark cf917ac
fix typing
Light2Dark 94a7dc5
slightly clearer types
Light2Dark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -63,7 +63,12 @@ import { | |
import { PythonIcon } from "../editor/cell/code/icons"; | ||
import { PreviewSQLTable } from "@/core/functions/FunctionRegistry"; | ||
import { useAsyncData } from "@/hooks/useAsyncData"; | ||
import { DatasourceLabel, EmptyState, RotatingChevron } from "./components"; | ||
import { | ||
DatasourceLabel, | ||
EmptyState, | ||
ItemSubtext, | ||
RotatingChevron, | ||
} from "./components"; | ||
|
||
const sortedTablesAtom = atom((get) => { | ||
const tables = get(datasetTablesAtom); | ||
|
@@ -186,6 +191,7 @@ export const DataSources: React.FC = () => { | |
> | ||
<SchemaList | ||
schemas={database.schemas} | ||
defaultSchema={connection.default_schema} | ||
engineName={connection.name} | ||
databaseName={database.name} | ||
hasSearch={hasSearch} | ||
|
@@ -285,11 +291,19 @@ const DatabaseItem: React.FC<{ | |
|
||
const SchemaList: React.FC<{ | ||
schemas: DatabaseSchema[]; | ||
defaultSchema?: string | null; | ||
engineName: string; | ||
databaseName: string; | ||
hasSearch: boolean; | ||
searchValue?: string; | ||
}> = ({ schemas, engineName, databaseName, hasSearch, searchValue }) => { | ||
}> = ({ | ||
schemas, | ||
defaultSchema, | ||
engineName, | ||
databaseName, | ||
hasSearch, | ||
searchValue, | ||
}) => { | ||
if (schemas.length === 0) { | ||
return <EmptyState content="No schemas available" className="pl-6" />; | ||
} | ||
|
@@ -310,6 +324,7 @@ const SchemaList: React.FC<{ | |
key={schema.name} | ||
databaseName={databaseName} | ||
schema={schema} | ||
isDefaultSchema={schema.name === defaultSchema} | ||
hasSearch={hasSearch} | ||
> | ||
<TableList | ||
|
@@ -319,6 +334,7 @@ const SchemaList: React.FC<{ | |
engine: engineName, | ||
database: databaseName, | ||
schema: schema.name, | ||
defaultSchema: defaultSchema, | ||
}} | ||
/> | ||
</SchemaItem> | ||
|
@@ -330,9 +346,10 @@ const SchemaList: React.FC<{ | |
const SchemaItem: React.FC<{ | ||
databaseName: string; | ||
schema: DatabaseSchema; | ||
isDefaultSchema?: boolean; | ||
children: React.ReactNode; | ||
hasSearch: boolean; | ||
}> = ({ databaseName, schema, children, hasSearch }) => { | ||
}> = ({ databaseName, schema, isDefaultSchema, children, hasSearch }) => { | ||
const [isExpanded, setIsExpanded] = React.useState(false); | ||
const [isSelected, setIsSelected] = React.useState(false); | ||
const uniqueValue = `${databaseName}:${schema.name}`; | ||
|
@@ -361,6 +378,8 @@ const SchemaItem: React.FC<{ | |
<span className={cn(isSelected && isExpanded && "font-semibold")}> | ||
{schema.name} | ||
</span> | ||
{/* Do we want this? They could change the default by executing USE schema.. */} | ||
{isDefaultSchema && <ItemSubtext content="default" />} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can remove for now? we can look if other SQL apps do this: |
||
</CommandItem> | ||
{isExpanded && children} | ||
</> | ||
|
@@ -371,6 +390,7 @@ interface SQLTableContext { | |
engine: string; | ||
database: string; | ||
schema: string; | ||
defaultSchema?: string | null; | ||
} | ||
|
||
const TableList: React.FC<{ | ||
|
@@ -441,8 +461,10 @@ const DatasetTableItem: React.FC<{ | |
maybeAddMarimoImport(autoInstantiate, createNewCell, lastFocusedCellId); | ||
let code = ""; | ||
if (sqlTableContext) { | ||
const { engine, schema } = sqlTableContext; | ||
code = `_df = mo.sql(f"SELECT * FROM ${schema}.${table.name} LIMIT 100", engine=${engine})`; | ||
const { engine, schema, defaultSchema } = sqlTableContext; | ||
const tableName = | ||
defaultSchema === schema ? table.name : `${schema}.${table.name}`; | ||
code = `_df = mo.sql(f"SELECT * FROM ${tableName} LIMIT 100", engine=${engine})`; | ||
} else { | ||
switch (table.source_type) { | ||
case "local": | ||
|
@@ -638,16 +660,12 @@ const DatasetColumnItem: React.FC<{ | |
<span>{column.name}</span> | ||
{isPrimaryKey && ( | ||
<Tooltip content="Primary Key" delayDuration={100}> | ||
<span className="text-xs text-black bg-gray-200 rounded px-1"> | ||
PK | ||
</span> | ||
<ItemSubtext content="PK" /> | ||
</Tooltip> | ||
)} | ||
{isIndexed && ( | ||
<Tooltip content="Indexed" delayDuration={100}> | ||
<span className="text-xs text-black bg-gray-200 rounded px-1"> | ||
IDX | ||
</span> | ||
<ItemSubtext content="IDX" /> | ||
</Tooltip> | ||
)} | ||
</div> | ||
|
@@ -837,8 +855,10 @@ function sqlCode( | |
sqlTableContext?: SQLTableContext, | ||
) { | ||
if (sqlTableContext) { | ||
const { engine, schema } = sqlTableContext; | ||
return `_df = mo.sql(f'SELECT ${column.name} FROM ${schema}.${table.name} LIMIT 100', engine=${engine})`; | ||
const { engine, schema, defaultSchema } = sqlTableContext; | ||
const tableName = | ||
defaultSchema === schema ? table.name : `${schema}.${table.name}`; | ||
return `_df = mo.sql(f"SELECT ${column.name} FROM ${tableName} LIMIT 100", engine=${engine})`; | ||
} | ||
return `_df = mo.sql(f'SELECT "${column.name}" FROM ${table.name} LIMIT 100')`; | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
bg-gray-200
won't support dark mode, and i think it could be slightly lightermaybe
bg-[var(--slate-8] text-[var(--slate-9]
?