Skip to content
Merged
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
8 changes: 4 additions & 4 deletions src/duckdb/generated_extension_loader_package_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int32_t duckdb_extension_core_functions_describe(duckdb_extension_descriptor *de
descriptor->version = 1;
descriptor->name = "core_functions";
descriptor->extension_version = EXT_VERSION_CORE_FUNCTIONS;
descriptor->api_version = "v2.0.1-alpha56662";
descriptor->api_version = "v2.0.1";
descriptor->entry_cpp = (void (*)(void))core_functions_duckdb_cpp_init;
return 0;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ int32_t duckdb_extension_parquet_describe(duckdb_extension_descriptor *descripto
descriptor->version = 1;
descriptor->name = "parquet";
descriptor->extension_version = EXT_VERSION_PARQUET;
descriptor->api_version = "v2.0.1-alpha56662";
descriptor->api_version = "v2.0.1";
descriptor->entry_cpp = (void (*)(void))parquet_duckdb_cpp_init;
return 0;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ int32_t duckdb_extension_icu_describe(duckdb_extension_descriptor *descriptor) {
descriptor->version = 1;
descriptor->name = "icu";
descriptor->extension_version = EXT_VERSION_ICU;
descriptor->api_version = "v2.0.1-alpha56662";
descriptor->api_version = "v2.0.1";
descriptor->entry_cpp = (void (*)(void))icu_duckdb_cpp_init;
return 0;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ int32_t duckdb_extension_json_describe(duckdb_extension_descriptor *descriptor)
descriptor->version = 1;
descriptor->name = "json";
descriptor->extension_version = EXT_VERSION_JSON;
descriptor->api_version = "v2.0.1-alpha56662";
descriptor->api_version = "v2.0.1";
descriptor->entry_cpp = (void (*)(void))json_duckdb_cpp_init;
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "1-alpha56662"
#define DUCKDB_PATCH_VERSION "1"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 0
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 2
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v2.0.1-alpha56662"
#define DUCKDB_VERSION "v2.0.1"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "a1854c4716"
#define DUCKDB_SOURCE_ID "8d78114e90"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
35 changes: 23 additions & 12 deletions src/duckdb/src/include/duckdb/parser/peg/inlined_grammar.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#pragma once

#include "duckdb/parser/peg/tokenizer/tokenizer.hpp"
#include "duckdb/parser/peg/matcher.hpp"

namespace duckdb {

//! Matches a dotted name spelled without quotes: 'carlopi.github.io', 'my-website.com'. The tokenizer cuts such a name
//! into words, '.' and '-' tokens; this matcher glues them back together as long as they touch (no whitespace or
//! comment in between) and the result is a dotted name (IsDottedName): labels of words joined by single dashes,
//! separated by single dots. Note that '--' starts a comment for the tokenizer, so a label with two dashes in a row
//! cannot be spelled unquoted at all; it is not a dotted name either way.
class DottedNameMatcher : public AtomicMatcher {
public:
static constexpr MatcherType TYPE = MatcherType::VARIABLE;

public:
DottedNameMatcher() : AtomicMatcher(TYPE) {
name = "DottedName";
}

MatcherResult MatchAtomic(MatchState &state) const override {
auto token = state.token_iterator.Current();
if (!token) {
return MatcherResult::Failure();
}
auto start_offset = token->offset;
string text;
idx_t end_offset = start_offset;
idx_t token_count = 0;
while (true) {
auto next = state.token_iterator.Current();
if (!next || next->offset != end_offset || !IsNamePart(*next)) {
break;
}
text += next->text;
end_offset = next->offset + next->length;
state.token_iterator.Advance();
token_count++;
}
if (token_count == 0 || !IsDottedName(text)) {
return MatcherResult::Failure();
}
state.UpdateMaxTokenIndex();
state.token_iterator.SetPreviousTokenType(TokenType::IDENTIFIER);
if (!state.BuildParseResult()) {
return MatcherResult::Success();
}
state.FoldIdentifier(text);
return state.AllocateParseResult<IdentifierParseResult>(text, optional_idx(start_offset),
optional_idx(end_offset - start_offset));
}

SuggestionType AddSuggestionInternal(MatchState &state) const override {
return SuggestionType::MANDATORY;
}

string ToString() const override {
return "DOTTED_NAME";
}

void InitializeFirstSet(MatcherFirstSet &first_set, const GrammarLiteralTable &table) const override {
first_set.class_mask = MatcherTokenClass::WORD | MatcherTokenClass::NUMBER;
}

//! A dotted name: two or more labels separated by single dots, each label one or more words joined by single
//! dashes, each word one or more letters, digits or '_' (bytes outside ASCII count as letters, so that a name like
//! münchen.de is a name here and gets the manager's answer rather than a syntax error). So no label starts or ends
//! with '-', and no two dashes touch
static bool IsDottedName(const string &text) {
idx_t label_count = 0;
idx_t word_length = 0;
for (idx_t i = 0; i <= text.size(); i++) {
auto c = i < text.size() ? text[i] : '.';
if (c == '.' || c == '-') {
// a separator ends a word, which must not be empty
if (word_length == 0) {
return false;
}
word_length = 0;
if (c == '.') {
label_count++;
}
continue;
}
if (!StringUtil::CharacterIsAlpha(c) && !StringUtil::CharacterIsDigit(c) && c != '_' &&
static_cast<unsigned char>(c) < 0x80) {
return false;
}
word_length++;
}
return label_count >= 2;
}

private:
//! A token that can be part of an unquoted dotted name: a plain word or number, or a lone '.' or '-'
static bool IsNamePart(const MatcherToken &token) {
if (token.text.empty()) {
return false;
}
switch (token.type) {
case TokenType::KEYWORD:
case TokenType::IDENTIFIER:
case TokenType::NUMBER_LITERAL:
return true;
case TokenType::OPERATOR:
return token.text == "." || token.text == "-";
default:
return false;
}
}
};

} // namespace duckdb
1 change: 1 addition & 0 deletions src/duckdb/src/include/duckdb/parser/peg/matcher/list.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "duckdb/parser/peg/matcher/arithmetic_operator_matcher.hpp"
#include "duckdb/parser/peg/matcher/choice_matcher.hpp"
#include "duckdb/parser/peg/matcher/end_of_input_matcher.hpp"
#include "duckdb/parser/peg/matcher/dotted_name_matcher.hpp"
#include "duckdb/parser/peg/matcher/identifier_matcher.hpp"
#include "duckdb/parser/peg/matcher/keyword_matcher.hpp"
#include "duckdb/parser/peg/matcher/list_matcher.hpp"
Expand Down
5 changes: 4 additions & 1 deletion src/duckdb/src/include/duckdb/parser/peg/peg_rule_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,9 @@ enum class PEGRuleId : uint32_t {
RegisterExternalResourceStmt,
DestroyExternalResourceStmt,
ExternalResourceKeyword,
ExternalResourceType,
ExternalResourceTypeName,
BareName,
ExternalResourceCreationOptions,
AttachToExternalResource,
ConnectToExternalResource,
Expand Down Expand Up @@ -843,7 +846,7 @@ enum class PEGRuleId : uint32_t {
CreateExtensionRepositoryFromHostStmt,
DropExtensionRepositoryStmt,
ExtensionRepositoryName,
ExtensionRepositoryHostName,
DottedName,
MergeIntoStatement,
MergeIntoUsingClause,
MergeMatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,12 @@ class PEGTransformerFactory {
FinalizeRegisterExternalResourceStmtTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue>
FinalizeDestroyExternalResourceStmtTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue> FinalizeExternalResourceTypeTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue>
FinalizeExternalResourceTypeNameTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue> FinalizeBareNameTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue>
FinalizeAttachToExternalResourceTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue>
Expand Down Expand Up @@ -2136,8 +2142,6 @@ class PEGTransformerFactory {
FinalizeDropExtensionRepositoryStmtTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue>
FinalizeExtensionRepositoryNameTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue>
FinalizeExtensionRepositoryHostNameTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue> FinalizeMergeIntoStatementTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
static arena_ptr<TransformResultValue> FinalizeMergeIntoUsingClauseTrampoline(PEGTransformer &transformer,
Expand Down Expand Up @@ -3207,7 +3211,7 @@ class PEGTransformerFactory {
unique_ptr<QueryNode> child);
static unique_ptr<QueryNode> TransformShowExternalResources(PEGTransformer &transformer, const ShowType &show_rule,
const bool &has_result,
optional<Identifier> show_external_resources_type);
optional<string> show_external_resources_type);
static unique_ptr<QueryNode> TransformShowExternalResourceTypes(PEGTransformer &transformer,
const ShowType &show_rule);
static unique_ptr<QueryNode> TransformShowDeprecatedSelect(PEGTransformer &transformer, const ShowType &show_rule,
Expand Down Expand Up @@ -3802,15 +3806,16 @@ class PEGTransformerFactory {
static unique_ptr<ParsedExpression> TransformExtractStringArgument(PEGTransformer &transformer,
const string &string_literal);
static unique_ptr<SQLStatement>
TransformCreateExternalResourceStmt(PEGTransformer &transformer, const string &string_literal,
TransformCreateExternalResourceStmt(PEGTransformer &transformer, const string &external_resource_type,
const optional<Identifier> &attach_alias,
const optional<vector<GenericCopyOption>> &external_resource_creation_options);
static unique_ptr<SQLStatement> TransformRegisterExternalResourceStmt(PEGTransformer &transformer,
const string &string_literal,
const string &external_resource_type,
const optional<Identifier> &attach_alias,
unique_ptr<ParsedExpression> expression);
static unique_ptr<SQLStatement> TransformDestroyExternalResourceStmt(PEGTransformer &transformer,
const Identifier &col_id);
static string TransformExternalResourceTypeName(PEGTransformer &transformer, const Identifier &bare_name);
static unique_ptr<SQLStatement> TransformAttachToExternalResource(
PEGTransformer &transformer, unique_ptr<ExternalResourceOptions> external_resource_source,
const Identifier &attach_alias, const optional<vector<GenericCopyOption>> &attach_options);
Expand All @@ -3819,7 +3824,7 @@ class PEGTransformerFactory {
unique_ptr<ExternalResourceOptions> external_resource_source,
const optional<vector<GenericCopyOption>> &attach_options);
static unique_ptr<ExternalResourceOptions> TransformExternalResourceCreateClause(
PEGTransformer &transformer, const string &string_literal,
PEGTransformer &transformer, const string &external_resource_type,
const optional<vector<GenericCopyOption>> &external_resource_creation_options);
static unique_ptr<ExternalResourceOptions> TransformExternalResourceReferenceClause(PEGTransformer &transformer,
const Identifier &col_id);
Expand Down Expand Up @@ -3891,8 +3896,6 @@ class PEGTransformerFactory {
static unique_ptr<SQLStatement> TransformDropExtensionRepositoryStmt(PEGTransformer &transformer,
const optional<bool> &if_exists,
const Identifier &col_id_or_string);
static Identifier TransformExtensionRepositoryHostName(PEGTransformer &transformer, const Identifier &col_id,
const vector<string> &dot_col_label);
static unique_ptr<SQLStatement>
TransformMergeIntoStatement(PEGTransformer &transformer, optional<CommonTableExpressionMap> with_clause,
unique_ptr<BaseTableRef> target_opt_alias, unique_ptr<TableRef> merge_into_using_clause,
Expand Down
73 changes: 51 additions & 22 deletions src/duckdb/src/main/extension/extension_repository_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,17 @@ static string RepositoryNameOfFile(const string &file_name) {
string ExtensionRepositoryManager::NormalizeRepositoryName(const string &name) {
string result;
if (!TryNormalizeRepositoryName(name, result)) {
string hint;
for (auto c : name) {
if (static_cast<unsigned char>(c) >= 0x80) {
hint = "\nAn internationalised host is spelled in its punycode form, 'xn--...', in quotes";
break;
}
}
throw InvalidInputException("Invalid extension repository name '%s': names cannot be empty and can only "
"contain letters, digits, '_', '-' and '.' (not at the start or the end, and not "
"two in a row)",
name);
"two in a row)%s",
name, hint);
}
return result;
}
Expand All @@ -389,29 +396,49 @@ static constexpr const idx_t METADATA_FORMAT_VERSION = 1;
//! and not localhost. A single word is not a host: it would be resolved through search domains to a host the user did
//! not name. There is no stricter test short of the public suffix list; this one keeps out what is certainly not a
//! public host
bool ExtensionRepositoryManager::IsHostName(const string &text) {
idx_t label_count = 0;
idx_t label_start = 0;
for (idx_t i = 0; i <= text.size(); i++) {
if (i < text.size() && text[i] != '.') {
auto c = text[i];
if (!StringUtil::CharacterIsAlpha(c) && !StringUtil::CharacterIsDigit(c) && c != '-') {
//! A host label: one or more words of letters and digits joined by single dashes, so no leading or trailing dash and
//! no two dashes touching - except the one place two dashes are legitimate, the 'xn--' that opens an internationalised
//! label in its punycode (A-label) form: 'xn--mnchen-3ya' for 'münchen'
static bool IsHostLabel(const string &label) {
idx_t start = 0;
if (label.size() > 4 && StringUtil::CIEquals(label.substr(0, 4), "xn--")) {
start = 4;
}
idx_t word_length = 0;
for (idx_t i = start; i <= label.size(); i++) {
auto c = i < label.size() ? label[i] : '-';
if (c == '-') {
if (word_length == 0) {
return false;
}
word_length = 0;
continue;
}
// end of a label
if (i == label_start || text[label_start] == '-' || text[i - 1] == '-') {
if (!StringUtil::CharacterIsAlpha(c) && !StringUtil::CharacterIsDigit(c)) {
return false;
}
label_count++;
label_start = i + 1;
word_length++;
}
return true;
}

bool ExtensionRepositoryManager::IsHostName(const string &text) {
// two or more labels separated by single dots, the last one letters only (an IPv4 literal is not a host), and not
// localhost
if (text.empty() || text.front() == '.' || text.back() == '.' || text.find("..") != string::npos) {
return false;
}
if (label_count < 2) {
auto labels = StringUtil::Split(text, '.');
if (labels.size() < 2) {
return false;
}
for (idx_t i = text.rfind('.') + 1; i < text.size(); i++) {
if (!StringUtil::CharacterIsAlpha(text[i])) {
for (auto &label : labels) {
if (!IsHostLabel(label)) {
return false;
}
}
for (auto c : labels.back()) {
if (!StringUtil::CharacterIsAlpha(c)) {
return false;
}
}
Expand Down Expand Up @@ -532,12 +559,14 @@ ExtensionRepositoryResolution ExtensionRepositoryManager::ResolveRepositoryFromH
// only a name that is a host on the public internet is reached: a single word would resolve through search
// domains to a host the user did not name, an IP literal or localhost is nobody's statement
if (!IsHostName(name)) {
throw InvalidInputException(
"Cannot create extension repository '%s': '%s' is not a host name. A host has two or "
"more labels of letters, digits and '-' separated by dots, the last one letters "
"only, and is not localhost\nUse `WITH PREFIX '<url>'` to name the repository's "
"location directly",
name_p, name);
throw InvalidInputException("Cannot create extension repository '%s': '%s' is not a host name. A host has two "
"or more labels separated by "
"dots, each label words of letters and digits joined by single dashes (or a "
"punycode label, 'xn--...'), the "
"last label letters only, and is not localhost\nUse `WITH PREFIX '<url>'` to name "
"the repository's location "
"directly",
name_p, name);
}
ExtensionRepositoryResolution resolution;
resolution.host = name;
Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/parser/peg/compiled_grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ terminal_rule_overrides_t ParsedGrammar::BuildTerminalRuleOverrides(const PEGKey
AddTerminalRuleOverride(overrides, "CopyOptionName",
make_uniq<ReservedIdentifierMatcher>(SuggestionState::SUGGEST_VARIABLE, keyword_helper));
AddTerminalRuleOverride(overrides, "NumberLiteral", make_uniq<NumberLiteralMatcher>());
AddTerminalRuleOverride(overrides, "DottedName", make_uniq<DottedNameMatcher>());
AddTerminalRuleOverride(overrides, "StringLiteral", make_uniq<StringLiteralMatcher>());
AddTerminalRuleOverride(overrides, "OperatorLiteral", make_uniq<OperatorMatcher>());
AddTerminalRuleOverride(overrides, "AnyOperatorLiteral",
Expand Down
5 changes: 4 additions & 1 deletion src/duckdb/src/parser/peg/peg_rule_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,9 @@ static const char *const PEG_RULE_NAMES[] = {
"RegisterExternalResourceStmt",
"DestroyExternalResourceStmt",
"ExternalResourceKeyword",
"ExternalResourceType",
"ExternalResourceTypeName",
"BareName",
"ExternalResourceCreationOptions",
"AttachToExternalResource",
"ConnectToExternalResource",
Expand Down Expand Up @@ -842,7 +845,7 @@ static const char *const PEG_RULE_NAMES[] = {
"CreateExtensionRepositoryFromHostStmt",
"DropExtensionRepositoryStmt",
"ExtensionRepositoryName",
"ExtensionRepositoryHostName",
"DottedName",
"MergeIntoStatement",
"MergeIntoUsingClause",
"MergeMatch",
Expand Down
Loading
Loading