Skip to content

Commit

Permalink
feature: add logs in table provisionning
Browse files Browse the repository at this point in the history
  • Loading branch information
Samox committed Feb 23, 2024
1 parent f7a2b33 commit 87091f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions frontend/src/pages/Overview/OverviewWithDuckDb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const OverviewWithDb = () => {
const [dualTableFromSqlQuery, setdualTableFromSqlQuery] =
useState<DualTableProps | null>(null);

console.log("dualTableFromSqlQuery", dualTableFromSqlQuery);

const loaderData = useOverviewLoaderData();
const searchParams = new URLSearchParams(window.location.search);

Expand Down Expand Up @@ -102,7 +100,7 @@ const OverviewWithDb = () => {
commitListData.isLoading
);

const topContainerValues = ["query", "lineage", null] as const;
const topContainerValues = ["lineage", "query", null] as const;

const [topContainer, setTopContainer] = useState<
(typeof topContainerValues)[number]
Expand Down Expand Up @@ -213,7 +211,9 @@ const OverviewWithDb = () => {

{selectedCommit ? (
<DiffTableContainer>
{dualTableData.isLoading ? (
{dualTableFromSqlQuery ? (
<DiffTable dualTableProps={dualTableFromSqlQuery} />
) : dualTableData.isLoading ? (
<Loader />
) : (
dualTableData.data && (
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/pages/Overview/SqlEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ type SqlEditorProps = {
setQueryResult: (result: DualTableProps) => void;
};

const SqlEditor = ({ dualTable }: SqlEditorProps) => {
const SqlEditor = ({ dualTable, setQueryResult }: SqlEditorProps) => {
const db = DuckDbProvider.useDuckDb();
useLoadSnapshotData(dualTable, db);

const [sql, setSQL] = useState("");
const [isRunning, setIsRunning] = useState(false);

const onValidation = async () => {
const onValidation = () => {
void handleValidation();
};

const handleValidation = async () => {
if (!db) {
console.error("DuckDB is not initialized.");
return;
Expand All @@ -40,6 +44,7 @@ const SqlEditor = ({ dualTable }: SqlEditorProps) => {
};
const dualTable = sqlToDualTableMapper(oldRows, newRows);
console.log("dualTable", dualTable);
setQueryResult(dualTable);
setIsRunning(false);
} catch (error) {
console.error(error);
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/pages/Overview/duck-db.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const useLoadSnapshotData = (
useEffect(() => {
const handleDualTableLoaded = async () => {
if (dualTableData && db && !hasEffectRun.current) {
console.log("dualTableData", dualTableData);
hasEffectRun.current = true;
await loadSnapshotData(dualTableData, db);
}
Expand All @@ -44,6 +43,7 @@ export const loadSnapshotData = async (
" VARCHAR, "
)} VARCHAR)`;
await db.query(createOldTableSql);
console.log("old_snapshot table created");
for (const row of oldData.data) {
if (row.isEmpty || row.isEllipsis) {
continue;
Expand All @@ -53,13 +53,14 @@ export const loadSnapshotData = async (
.join("', '")}')`;
await db.query(insertSql);
}
console.log("old_snapshot data inserted created");

const newData = dualTableProps.tableProps1;

const createNewTableSql = `CREATE TABLE new_snapshot (${newData.headers.join(
" VARCHAR, "
)} VARCHAR)`;
await db.query(createNewTableSql);
console.log("new_snapshot table created");
for (const row of newData.data) {
if (row.isEmpty || row.isEllipsis) {
continue;
Expand All @@ -69,5 +70,6 @@ export const loadSnapshotData = async (
.join("', '")}')`;
await db.query(insertSql);
}
console.log("new_snapshot data inserted created");
return;
};

0 comments on commit 87091f6

Please sign in to comment.