Repository: duckdb/duckdb
File: src/function/table/system/duckdb_functions.cpp (C++)

Code before:
	// parameter_types, LogicalType::LIST(LogicalType::VARCHAR)
	output.SetValue(col++, output_offset, parameter_types);

	// varargs, LogicalType::VARCHAR
	output.SetValue(col++, output_offset, Value(LogicalTypeId::VARCHAR));

	// macro_definition, LogicalType::VARCHAR
	output.SetValue(col++, output_offset, Value(LogicalTypeId::VARCHAR));

	// has_side_effects, LogicalType::BOOLEAN
	output.SetValue(col++, output_offset, Value(LogicalTypeId::VARCHAR));

	// internal, LogicalType::BOOLEAN
	output.SetValue(col++, output_offset, Value::BOOLEAN(true));

	// function_oid, LogicalType::BIGINT
	output.SetValue(col++, output_offset, Value(LogicalTypeId::BIGINT));

	// examples, LogicalType::LIST(LogicalType::VARCHAR)
	output.SetValue(col++, output_offset, Value::LIST(LogicalType::VARCHAR, {}));

	// stability, LogicalType::VARCHAR
	output.SetValue(col++, output_offset, Value(LogicalTypeId::VARCHAR));

	// categories, LogicalType::LIST(LogicalType::VARCHAR)
	output.SetValue(col++, output_offset, Value::LIST(LogicalType::VARCHAR, {}));
}

static bool Finished(const DuckDBFunctionsData &data) {
	if (data.offset < data.entries.size()) {
		return false;
	}
	if (data.window_iterator->name == nullptr) {
		return true;
	}
	return false;
}

void DuckDBFunctionsFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
	auto &data = data_p.global_state->Cast<DuckDBFunctionsData>();
	if (Finished(data)) {
		// finished returning values
		return;
	}
	// start returning values
	// either fill up the chunk or return all the remaining columns
	idx_t count = 0;
	while (data.offset < data.entries.size() && count < STANDARD_VECTOR_SIZE) {
		auto &entry = data.entries[data.offset].get().Cast<FunctionEntry>();
		bool finished;


Review comment (refactor):
Is it possible to not duplicate the code that sets these columns by implementing a custom extractor like we did for scalar/aggregate/macro/tablemacro/tablefunction?

Code after:
		WindowFunctionCatalogEntry function(default_schema, name, {LogicalType::TEMPLATE("T")},
		                                    LogicalType::TEMPLATE("T"));
		ExtractFunctionData<WindowFunctionCatalogEntry, WindowFunctionExtractor>(function, 0, output, output_offset);
		break;
	}
	case ExpressionType::WINDOW_NTH_VALUE: {
		WindowFunctionCatalogEntry function(default_schema, name, {LogicalType::TEMPLATE("T"), LogicalType::BIGINT},
		                                    LogicalType::TEMPLATE("T"));
		ExtractFunctionData<WindowFunctionCatalogEntry, WindowFunctionExtractor>(function, 0, output, output_offset);
		break;
	}
	case ExpressionType::WINDOW_ROW_NUMBER:
	case ExpressionType::WINDOW_RANK:
	case ExpressionType::WINDOW_RANK_DENSE: {
		WindowFunctionCatalogEntry function(default_schema, name, {}, LogicalType::BIGINT);
		ExtractFunctionData<WindowFunctionCatalogEntry, WindowFunctionExtractor>(function, 0, output, output_offset);
		break;
	}
	case ExpressionType::WINDOW_NTILE: {
		WindowFunctionCatalogEntry function(default_schema, name, {LogicalType::BIGINT}, LogicalType::BIGINT);
		ExtractFunctionData<WindowFunctionCatalogEntry, WindowFunctionExtractor>(function, 0, output, output_offset);
		break;
	}
	case ExpressionType::WINDOW_PERCENT_RANK:
	case ExpressionType::WINDOW_CUME_DIST: {
		WindowFunctionCatalogEntry function(default_schema, name, {}, LogicalType::DOUBLE);
		ExtractFunctionData<WindowFunctionCatalogEntry, WindowFunctionExtractor>(function, 0, output, output_offset);
		break;
	}
	case ExpressionType::WINDOW_LAG:
	case ExpressionType::WINDOW_LEAD: {
		WindowFunctionCatalogEntry function(
		    default_schema, name, {LogicalType::TEMPLATE("T"), LogicalType::BIGINT, LogicalType::TEMPLATE("T")},
		    LogicalType::TEMPLATE("T"));
		ExtractFunctionData<WindowFunctionCatalogEntry, WindowFunctionExtractor>(function, 0, output, output_offset);
		break;
	}
	default:
		throw InternalException("Window function '%s' not implemented", name);
	}
}

static bool Finished(const DuckDBFunctionsData &data) {
	if (data.offset < data.entries.size()) {
		return false;
	}
	if (data.window_iterator->name == nullptr) {
		return true;
	}
	return false;
}