Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Remove the bug that assumes only one parquet file exists for the episodes metadata (#11)
Browse files
src/app/[org]/[dataset]/[episode]/fetch-data.ts
CHANGED
|
@@ -481,7 +481,19 @@ async function loadEpisodeDataV3(
|
|
| 481 |
// Convert BigInt to number if needed
|
| 482 |
const fromIndex = Number(episodeMetadata.dataset_from_index || 0);
|
| 483 |
const toIndex = Number(episodeMetadata.dataset_to_index || fullData.length);
|
| 484 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
|
| 486 |
if (episodeData.length === 0) {
|
| 487 |
return { chartDataGroups: [], ignoredColumns: [], task: undefined };
|
|
@@ -924,47 +936,50 @@ async function loadEpisodeMetadataV3Simple(
|
|
| 924 |
version: string,
|
| 925 |
episodeId: number,
|
| 926 |
): Promise<any> {
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 932 |
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
if (episodesData.length === 0) {
|
| 938 |
-
throw new Error("No episode metadata found");
|
| 939 |
-
}
|
| 940 |
-
|
| 941 |
-
// Find the row for the requested episode
|
| 942 |
-
let episodeRow = null;
|
| 943 |
-
|
| 944 |
-
for (let i = 0; i < episodesData.length; i++) {
|
| 945 |
-
const row = episodesData[i];
|
| 946 |
-
const parsedRow = parseEpisodeRowSimple(row);
|
| 947 |
|
| 948 |
-
if (
|
| 949 |
-
|
| 950 |
-
|
|
|
|
| 951 |
}
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 960 |
}
|
|
|
|
|
|
|
|
|
|
| 961 |
}
|
| 962 |
-
|
| 963 |
-
// Convert the row to a usable format
|
| 964 |
-
return parseEpisodeRowSimple(episodeRow);
|
| 965 |
-
} catch (error) {
|
| 966 |
-
throw error;
|
| 967 |
}
|
|
|
|
|
|
|
|
|
|
| 968 |
}
|
| 969 |
|
| 970 |
// Simple parser for episode row - focuses on key fields for episodes
|
|
|
|
| 481 |
// Convert BigInt to number if needed
|
| 482 |
const fromIndex = Number(episodeMetadata.dataset_from_index || 0);
|
| 483 |
const toIndex = Number(episodeMetadata.dataset_to_index || fullData.length);
|
| 484 |
+
|
| 485 |
+
// Find the starting index of this parquet file by checking the first row's index
|
| 486 |
+
// This handles the case where episodes are split across multiple parquet files
|
| 487 |
+
let fileStartIndex = 0;
|
| 488 |
+
if (fullData.length > 0 && fullData[0].index !== undefined) {
|
| 489 |
+
fileStartIndex = Number(fullData[0].index);
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
// Adjust indices to be relative to this file's starting position
|
| 493 |
+
const localFromIndex = Math.max(0, fromIndex - fileStartIndex);
|
| 494 |
+
const localToIndex = Math.min(fullData.length, toIndex - fileStartIndex);
|
| 495 |
+
|
| 496 |
+
const episodeData = fullData.slice(localFromIndex, localToIndex);
|
| 497 |
|
| 498 |
if (episodeData.length === 0) {
|
| 499 |
return { chartDataGroups: [], ignoredColumns: [], task: undefined };
|
|
|
|
| 936 |
version: string,
|
| 937 |
episodeId: number,
|
| 938 |
): Promise<any> {
|
| 939 |
+
// Pattern: meta/episodes/chunk-{chunk_index:03d}/file-{file_index:03d}.parquet
|
| 940 |
+
// Most datasets have all episodes in chunk-000/file-000, but episodes can be split across files
|
| 941 |
+
|
| 942 |
+
let episodeRow = null;
|
| 943 |
+
let fileIndex = 0;
|
| 944 |
+
const chunkIndex = 0; // Episodes are typically in chunk-000
|
| 945 |
+
|
| 946 |
+
// Try loading episode metadata files until we find the episode
|
| 947 |
+
while (!episodeRow) {
|
| 948 |
+
const episodesMetadataPath = `meta/episodes/chunk-${chunkIndex.toString().padStart(3, "0")}/file-${fileIndex.toString().padStart(3, "0")}.parquet`;
|
| 949 |
+
const episodesMetadataUrl = buildVersionedUrl(repoId, version, episodesMetadataPath);
|
| 950 |
|
| 951 |
+
try {
|
| 952 |
+
const arrayBuffer = await fetchParquetFile(episodesMetadataUrl);
|
| 953 |
+
const episodesData = await readParquetAsObjects(arrayBuffer, []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 954 |
|
| 955 |
+
if (episodesData.length === 0) {
|
| 956 |
+
// Empty file, try next one
|
| 957 |
+
fileIndex++;
|
| 958 |
+
continue;
|
| 959 |
}
|
| 960 |
+
|
| 961 |
+
// Find the row for the requested episode by episode_index
|
| 962 |
+
for (const row of episodesData) {
|
| 963 |
+
const parsedRow = parseEpisodeRowSimple(row);
|
| 964 |
+
|
| 965 |
+
if (parsedRow.episode_index === episodeId) {
|
| 966 |
+
episodeRow = row;
|
| 967 |
+
break;
|
| 968 |
+
}
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
if (!episodeRow) {
|
| 972 |
+
// Not in this file, try the next one
|
| 973 |
+
fileIndex++;
|
| 974 |
}
|
| 975 |
+
} catch (error) {
|
| 976 |
+
// File doesn't exist - episode not found
|
| 977 |
+
throw new Error(`Episode ${episodeId} not found in metadata (searched up to file-${fileIndex.toString().padStart(3, "0")}.parquet)`);
|
| 978 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 979 |
}
|
| 980 |
+
|
| 981 |
+
// Convert the row to a usable format
|
| 982 |
+
return parseEpisodeRowSimple(episodeRow);
|
| 983 |
}
|
| 984 |
|
| 985 |
// Simple parser for episode row - focuses on key fields for episodes
|