Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "all",
"printWidth": 120,
"tabWidth": 2,
"endOfLine": "auto"
}
33 changes: 7 additions & 26 deletions apps/demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,18 @@ import { GitBranch, Github } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@meta-sql/ui";
import { SQLEditor } from "./components/editor";
import { LineageGraph } from "./components/lineage/LineageGraph";
import type { ColumnLineageDatasetFacet } from "@meta-sql/open-lineage";
import type { Schema } from "@meta-sql/lineage";
import type { getExtendedLineage, Schema } from "@meta-sql/lineage";

// Use the actual return type from getLineage
type LineageResult = ColumnLineageDatasetFacet["fields"];
type LineageResult = ReturnType<typeof getExtendedLineage>;

// Default schema matching the sample queries
const defaultSchema: Schema = {
namespace: "default",
tables: [
{
name: "product_sales",
columns: [
"id",
"product_id",
"quantity_sold",
"unit_price",
"sale_date",
"store_id",
"discount_percentage",
],
columns: ["id", "product_id", "quantity_sold", "unit_price", "sale_date", "store_id", "discount_percentage"],
},
{
name: "stores",
Expand Down Expand Up @@ -64,9 +55,7 @@ export default function App() {
<div className="flex items-center gap-3">
<div className="flex items-center gap-2">
<GitBranch className="h-6 w-6 text-main" />
<h1 className="text-xl font-bold text-foreground">
@meta-sql/lineage
</h1>
<h1 className="text-xl font-bold text-foreground">@meta-sql/lineage</h1>
</div>
<div className="hidden md:block text-sm text-foreground/70">
Interactive Demo - SQL Column Lineage Analysis Package
Expand Down Expand Up @@ -96,24 +85,16 @@ export default function App() {
<CardTitle>SQL Editor</CardTitle>
</CardHeader>
<CardContent className="h-[calc(100%-theme(spacing.20))]">
<SQLEditor
onQueryParsed={handleQueryParsed}
schema={schema}
className="h-full"
/>
<SQLEditor onQueryParsed={handleQueryParsed} schema={schema} className="h-full" />
</CardContent>
</Card>

{/* Right Panel - Lineage Graph */}
<Card className="flex-1 bg-secondary-background shadow-shadow relative">
<CardContent className="absolute inset-0 p-0">
<LineageGraph
lineageData={lineageData || {}}
schema={schema}
className="h-full w-full"
/>
<LineageGraph lineageData={lineageData?.fields || {}} schema={schema} className="h-full w-full" />
</CardContent>
<CardHeader className="relative z- 10 bg-transparent">
<CardHeader className="relative z-10 bg-transparent">
<CardTitle>Data Lineage Graph</CardTitle>
</CardHeader>
</Card>
Expand Down
53 changes: 11 additions & 42 deletions apps/demo/src/components/editor/SQLEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ import {
PopoverContent,
PopoverTrigger,
} from "@meta-sql/ui";
import {
FileText,
AlertCircle,
CheckCircle,
CheckIcon,
ChevronsUpDown,
} from "lucide-react";
import { getLineage, type Schema } from "@meta-sql/lineage";
import type { ColumnLineageDatasetFacet } from "@meta-sql/open-lineage";
import { FileText, AlertCircle, CheckCircle, CheckIcon, ChevronsUpDown } from "lucide-react";
import { getExtendedLineage, type Schema } from "@meta-sql/lineage";
import { Parser } from "node-sql-parser";
import { sampleQueries, type SupportedDialect } from "./sampleQueries.js";
import { cn } from "@meta-sql/ui/lib/utils";

// Use the actual return type from getLineage
type LineageResult = ColumnLineageDatasetFacet["fields"];
type LineageResult = ReturnType<typeof getExtendedLineage>;

const dialectOptions = [
{
Expand Down Expand Up @@ -56,20 +49,12 @@ const dialectOptions = [
] satisfies Array<{ value: SupportedDialect; label: string }>;

interface SQLEditorProps {
onQueryParsed: (
lineageResult: LineageResult,
query: string,
dialect: string
) => void;
onQueryParsed: (lineageResult: LineageResult, query: string, dialect: string) => void;
schema?: Schema;
className?: string;
}

export const SQLEditor: React.FC<SQLEditorProps> = ({
onQueryParsed,
schema,
className = "",
}) => {
export const SQLEditor: React.FC<SQLEditorProps> = ({ onQueryParsed, schema, className = "" }) => {
const [query, setQuery] = useState("");
const [dialect, setDialect] = useState<SupportedDialect>("mysql");
const [open, setOpen] = useState(false);
Expand All @@ -96,17 +81,15 @@ export const SQLEditor: React.FC<SQLEditorProps> = ({
};

// Get column lineage and update the graph
const lineageResult = getLineage(firstStatement, lineageSchema);
const lineageResult = getExtendedLineage(firstStatement, lineageSchema);

onQueryParsed(lineageResult, query, dialect);

setValidationResult({ isValid: true, errors: [] });
} else {
setValidationResult({
isValid: false,
errors: [
"Only SELECT statements are supported for lineage analysis",
],
errors: ["Only SELECT statements are supported for lineage analysis"],
});
}
} else {
Expand All @@ -120,9 +103,7 @@ export const SQLEditor: React.FC<SQLEditorProps> = ({

setValidationResult({
isValid: false,
errors: [
error instanceof Error ? error.message : "Unknown parsing error",
],
errors: [error instanceof Error ? error.message : "Unknown parsing error"],
});
}
} else {
Expand Down Expand Up @@ -152,10 +133,7 @@ export const SQLEditor: React.FC<SQLEditorProps> = ({
aria-expanded={open}
className="w-[200px] justify-between"
>
{dialect
? dialectOptions.find((option) => option.value === dialect)
?.label
: "Select dialect..."}
{dialect ? dialectOptions.find((option) => option.value === dialect)?.label : "Select dialect..."}
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
Expand All @@ -175,12 +153,7 @@ export const SQLEditor: React.FC<SQLEditorProps> = ({
}}
>
<CheckIcon
className={cn(
"mr-2 h-4 w-4",
dialect === option.value
? "opacity-100"
: "opacity-0"
)}
className={cn("mr-2 h-4 w-4", dialect === option.value ? "opacity-100" : "opacity-0")}
/>
{option.label}
</CommandItem>
Expand Down Expand Up @@ -248,11 +221,7 @@ export const SQLEditor: React.FC<SQLEditorProps> = ({
</Badge>
<div className="flex flex-col gap-1">
{validationResult.errors.map((error, index) => (
<Badge
key={index}
variant="neutral"
className="text-wrap text-ellipsis inline max-w-3xl"
>
<Badge key={index} variant="neutral" className="text-wrap text-ellipsis inline max-w-3xl">
{error}
</Badge>
))}
Expand Down
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading