Skip to content

Commit b509fb9

Browse files
committed
Use pg_lake list as default, fall back to crunchy if it does not exist
1 parent 19190d9 commit b509fb9

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#pragma once
22

3-
#define DEFAULT_FILE_LIST_FUNCTION "crunchy_lake.list_files"
3+
#define DEFAULT_FILE_LIST_FUNCTION "lake_file.list"
4+
#define ORIGINAL_DEFAULT_FILE_LIST_FUNCTION "crunchy_lake.list_files"
45

56
extern char *DefaultFileListFunction;
67

78
void InitializeFileListPipelineState(char *pipelineName, char *prefix, bool batched, char *listFunction, int maxBatchSize);
89
void RemoveProcessedFileList(char *pipelineName);
910
void ExecuteFileListPipeline(char *pipelineName, char *command);
11+
bool ListFunctionExists(char *listFunction);
1012
char *SanitizeListFunction(char *listFunction);
1113
void InsertProcessedFile(char *pipelineName, char *path);

src/file_list.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,26 @@ RemoveProcessedFileList(char *pipelineName)
541541
}
542542

543543

544+
/*
545+
* ListFunctionExists determines whether the given list function
546+
* exists.
547+
*/
548+
bool
549+
ListFunctionExists(char *listFunction)
550+
{
551+
#if (PG_VERSION_NUM >= 160000)
552+
List *names = stringToQualifiedNameList(listFunction, NULL);
553+
#else
554+
List *names = stringToQualifiedNameList(listFunction);
555+
#endif
556+
Oid argTypes[] = {TEXTOID};
557+
bool missingOk = true;
558+
Oid functionId = LookupFuncName(names, 1, argTypes, missingOk);
559+
560+
return OidIsValid(functionId);
561+
}
562+
563+
544564
/*
545565
* SanitizeListFunction qualifies a list function name and errors
546566
* if the function cannot be found.

src/pipeline.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,30 @@ incremental_create_file_list_pipeline(PG_FUNCTION_ARGS)
221221
char *pipelineName = text_to_cstring(PG_GETARG_TEXT_P(0));
222222
char *prefix = text_to_cstring(PG_GETARG_TEXT_P(1));
223223
char *command = text_to_cstring(PG_GETARG_TEXT_P(2));
224-
char *listFunction = PG_ARGISNULL(3) ? DefaultFileListFunction : text_to_cstring(PG_GETARG_TEXT_P(3));
224+
char *listFunction = PG_ARGISNULL(3) ? NULL : text_to_cstring(PG_GETARG_TEXT_P(3));
225225
bool batched = PG_ARGISNULL(4) ? false : PG_GETARG_BOOL(4);
226226
int maxBatchSize = PG_ARGISNULL(5) ? 0 : PG_GETARG_INT32(5);
227227
char *schedule = PG_ARGISNULL(6) ? NULL : text_to_cstring(PG_GETARG_TEXT_P(6));
228228
bool executeImmediately = PG_ARGISNULL(7) ? false : PG_GETARG_BOOL(7);
229229
char *searchPath = pstrdup(namespace_search_path);
230230

231+
if (listFunction == NULL)
232+
{
233+
/*
234+
* Default to pg_lake, but fall back to original list function
235+
* if it does not exist for backwards compatibility.
236+
*/
237+
if (strcmp(DefaultFileListFunction, DEFAULT_FILE_LIST_FUNCTION) == 0 &&
238+
!ListFunctionExists(DefaultFileListFunction))
239+
{
240+
listFunction = ORIGINAL_DEFAULT_FILE_LIST_FUNCTION;
241+
}
242+
else
243+
{
244+
listFunction = DefaultFileListFunction;
245+
}
246+
}
247+
231248
/* validate and sanitize function name */
232249
listFunction = SanitizeListFunction(listFunction);
233250

0 commit comments

Comments
 (0)