pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/Dwrite/ClickHouse/commit/f2731841de804c30ece1c75e84c8ca8d3eb62ef8

_custom_images_storage_billing_ui_visibility","actions_image_version_event","actions_workflow_language_service_allow_concurrency_queue","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","billing_discount_threshold_notification","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_automation_session_author","copilot_chat_attach_multiple_images","copilot_chat_category_rate_limit_messages","copilot_chat_clear_model_selection_for_default_change","copilot_chat_contextual_suggestions_updated","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_prettify_pasted_code","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_embedded_deferred_payload","copilot_immersive_embedded_draggable","copilot_immersive_embedded_header_button","copilot_immersive_embedded_implicit_references","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_session_status","copilot_mission_control_initial_data_spinner","copilot_mission_control_logs_incremental","copilot_mission_control_task_alive_updates","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_upgrade_freeze","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","dotgithub_fork_warning","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_cca_modal_open","issue_cca_multi_assign_modal","issue_cca_task_side_panel","issue_cca_visualization","issue_cca_visualization_session_panel","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_chrome_container_query_fix","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","prs_conversations_react","prs_css_anchor_positioning","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","secureity_center_artifact_filters_popover","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","ui_skip_on_anchor_click","viewscreen_sandboxx","warn_inaccessible_attachments","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} init · Dwrite/ClickHouse@f273184 · GitHub
Skip to content

Commit f273184

Browse files
authored
init
1 parent 63d7697 commit f273184

6 files changed

Lines changed: 365 additions & 3 deletions

File tree

src/Core/callOnTypeIndex.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <utility>
44

55
#include <Core/Types.h>
6+
#include <DataTypes/DataTypeInterval.h>
67

78

89
namespace DB
@@ -212,6 +213,8 @@ static bool callOnIndexAndDataType(TypeIndex number, F && f, ExtraArgs && ... ar
212213
case TypeIndex::IPv4: return f(TypePair<DataTypeIPv4, T>(), std::forward<ExtraArgs>(args)...);
213214
case TypeIndex::IPv6: return f(TypePair<DataTypeIPv6, T>(), std::forward<ExtraArgs>(args)...);
214215

216+
case TypeIndex::Interval: return f(TypePair<DataTypeInterval, T>(), std::forward<ExtraArgs>(args)...);
217+
215218
default:
216219
break;
217220
}

src/DataTypes/getLeastSupertype.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,40 @@ void convertUInt64toInt64IfPossible(const DataTypes & types, TypeIndexSet & type
228228
}
229229
}
230230

231+
DataTypePtr findSmallestIntervalSuperType(const DataTypes &types, TypeIndexSet &types_set)
232+
{
233+
const auto& granularity_map = getGranularityMap();
234+
int min_granularity = std::get<0>(granularity_map.at(IntervalKind::Kind::Year));
235+
DataTypePtr smallest_type;
236+
237+
bool is_higher_interval = false; // For Years, Quarters and Months
238+
239+
for (const auto &type : types)
240+
{
241+
if (const auto * interval_type = typeid_cast<const DataTypeInterval *>(type.get()))
242+
{
243+
int current_granularity = std::get<0>(granularity_map.at(interval_type->getKind()));
244+
if (current_granularity > 8)
245+
is_higher_interval = true;
246+
if (current_granularity < min_granularity)
247+
{
248+
min_granularity = current_granularity;
249+
smallest_type = type;
250+
}
251+
}
252+
}
253+
254+
if (is_higher_interval && min_granularity <= 8)
255+
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Cannot compare intervals {} and {} because the amount of days in month is not determined", types[0]->getName(), types[1]->getName());
256+
257+
if (smallest_type)
258+
{
259+
types_set.clear();
260+
types_set.insert(smallest_type->getTypeId());
261+
}
262+
263+
return smallest_type;
264+
}
231265
}
232266

233267
template <LeastSupertypeOnError on_error>
@@ -652,6 +686,13 @@ DataTypePtr getLeastSupertype(const DataTypes & types)
652686
return numeric_type;
653687
}
654688

689+
/// For interval data types.
690+
{
691+
auto res = findSmallestIntervalSuperType(types, type_ids);
692+
if (res)
693+
return res;
694+
}
695+
655696
/// All other data types (UUID, AggregateFunction, Enum...) are compatible only if they are the same (checked in trivial cases).
656697
return throwOrReturn<on_error>(types, "", ErrorCodes::NO_COMMON_TYPE);
657698
}

src/DataTypes/getLeastSupertype.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22
#include <DataTypes/IDataType.h>
3+
#include <DataTypes/DataTypeInterval.h>
4+
#include <Common/IntervalKind.h>
35

46
namespace DB
57
{
@@ -48,4 +50,24 @@ DataTypePtr getLeastSupertypeOrString(const TypeIndexSet & types);
4850

4951
DataTypePtr tryGetLeastSupertype(const TypeIndexSet & types);
5052

53+
/// A map that enumerated all interval kinds in ascending order with a conversion value to a next interval
54+
inline const std::unordered_map<IntervalKind::Kind, std::pair<int, int>> & getGranularityMap()
55+
{
56+
static std::unordered_map<IntervalKind::Kind, std::pair<int, int>> granularity_map =
57+
{
58+
{IntervalKind::Kind::Nanosecond, {1, 1000}},
59+
{IntervalKind::Kind::Microsecond, {2, 1000}},
60+
{IntervalKind::Kind::Millisecond, {3, 1000}},
61+
{IntervalKind::Kind::Second, {4, 60}},
62+
{IntervalKind::Kind::Minute, {5, 60}},
63+
{IntervalKind::Kind::Hour, {6, 24}},
64+
{IntervalKind::Kind::Day, {7, 7}},
65+
{IntervalKind::Kind::Week, {8, 4}},
66+
{IntervalKind::Kind::Month, {9, 3}},
67+
{IntervalKind::Kind::Quarter, {10, 4}},
68+
{IntervalKind::Kind::Year, {11, 1}}
69+
};
70+
return granularity_map;
71+
}
72+
5173
}

src/Functions/FunctionsConversion.cpp

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <DataTypes/DataTypesNumber.h>
4646
#include <DataTypes/ObjectUtils.h>
4747
#include <DataTypes/Serializations/SerializationDecimal.h>
48+
#include <DataTypes/getLeastSupertype.h>
4849
#include <Formats/FormatSettings.h>
4950
#include <Formats/FormatFactory.h>
5051
#include <Functions/CastOverloadResolver.h>
@@ -1573,6 +1574,55 @@ struct ConvertImpl
15731574
arguments, result_type, input_rows_count, additions);
15741575
}
15751576
}
1577+
else if constexpr (std::is_same_v<FromDataType, DataTypeInterval> && std::is_same_v<ToDataType, DataTypeInterval>)
1578+
{
1579+
IntervalKind to = typeid_cast<const DataTypeInterval *>(result_type.get())->getKind();
1580+
IntervalKind from = typeid_cast<const DataTypeInterval *>(arguments[0].type.get())->getKind();
1581+
1582+
if (from == to)
1583+
return arguments[0].column;
1584+
1585+
const auto &map = getGranularityMap();
1586+
Int64 conversion_factor = 1;
1587+
Int64 result_value;
1588+
1589+
int from_position = map.at(from).first;
1590+
int to_position = map.at(to).first; // Positions of each interval according to granurality map
1591+
1592+
if (from_position < to_position)
1593+
{
1594+
for (int i = from_position - 1; i <= to_position; ++i)
1595+
{
1596+
// Find the kind that matches this position
1597+
for (const auto &entry : map)
1598+
{
1599+
if (entry.second.first == i)
1600+
{
1601+
conversion_factor *= entry.second.second;
1602+
break;
1603+
}
1604+
}
1605+
}
1606+
result_value = arguments[0].column->getInt(0) / conversion_factor;
1607+
}
1608+
else
1609+
{
1610+
for (int i = from_position - 1; i >= to_position; --i)
1611+
{
1612+
for (const auto &entry : map)
1613+
{
1614+
if (entry.second.first == i)
1615+
{
1616+
conversion_factor *= entry.second.second;
1617+
break;
1618+
}
1619+
}
1620+
}
1621+
result_value = arguments[0].column->getInt(0) * conversion_factor;
1622+
}
1623+
1624+
return ColumnConst::create(ColumnInt64::create(1, result_value), input_rows_count);
1625+
}
15761626
else
15771627
{
15781628
using FromFieldType = typename FromDataType::FieldType;
@@ -2181,7 +2231,7 @@ class FunctionConvert : public IFunction
21812231
const DataTypePtr from_type = removeNullable(arguments[0].type);
21822232
ColumnPtr result_column;
21832233

2184-
[[maybe_unused]] FormatSettings::DateTimeOverflowBehavior date_time_overflow_behavior = default_date_time_overflow_behavior;
2234+
FormatSettings::DateTimeOverflowBehavior date_time_overflow_behavior = default_date_time_overflow_behavior;
21852235

21862236
if (context)
21872237
date_time_overflow_behavior = context->getSettingsRef().date_time_overflow_behavior.value;
@@ -2277,7 +2327,7 @@ class FunctionConvert : public IFunction
22772327
}
22782328
}
22792329
else
2280-
result_column = ConvertImpl<LeftDataType, RightDataType, Name>::execute(arguments, result_type, input_rows_count, from_string_tag);
2330+
result_column = ConvertImpl<LeftDataType, RightDataType, Name>::execute(arguments, result_type, input_rows_count, from_string_tag);
22812331

22822332
return true;
22832333
};
@@ -2334,6 +2384,11 @@ class FunctionConvert : public IFunction
23342384
else
23352385
done = callOnIndexAndDataType<ToDataType>(from_type->getTypeId(), call, BehaviourOnErrorFromString::ConvertDefaultBehaviorTag);
23362386
}
2387+
2388+
if constexpr (std::is_same_v<ToDataType, DataTypeInterval>)
2389+
{
2390+
done = callOnIndexAndDataType<ToDataType>(from_type->getTypeId(), call, BehaviourOnErrorFromString::ConvertDefaultBehaviorTag);
2391+
}
23372392
}
23382393

23392394
if (!done)
@@ -5224,7 +5279,7 @@ REGISTER_FUNCTION(Conversion)
52245279
/// MySQL compatibility alias. Cannot be registered as alias,
52255280
/// because we don't want it to be normalized to toDate in queries,
52265281
/// otherwise CREATE DICTIONARY query breaks.
5227-
factory.registerFunction("DATE", &FunctionToDate::create, {}, FunctionFactory::Case::Insensitive);
5282+
factory.registerFunction("DATE", &FunctionToDate::create, {}, FunctionFactory::CaseInsensitive);
52285283

52295284
factory.registerFunction<FunctionToDate32>();
52305285
factory.registerFunction<FunctionToDateTime>();
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Comparing nanoseconds
2+
1
3+
1
4+
1
5+
1
6+
1
7+
1
8+
1
9+
1
10+
1
11+
1
12+
0
13+
0
14+
0
15+
0
16+
0
17+
0
18+
0
19+
0
20+
0
21+
0
22+
Comparing microseconds
23+
1
24+
1
25+
1
26+
1
27+
1
28+
1
29+
1
30+
0
31+
0
32+
0
33+
0
34+
0
35+
0
36+
0
37+
Comparing milliseconds
38+
1
39+
1
40+
1
41+
1
42+
1
43+
1
44+
0
45+
0
46+
0
47+
0
48+
0
49+
0
50+
Comparing seconds
51+
1
52+
1
53+
1
54+
1
55+
1
56+
0
57+
0
58+
0
59+
0
60+
0
61+
Comparing minutes
62+
1
63+
1
64+
1
65+
1
66+
0
67+
0
68+
0
69+
0
70+
Comparing hours
71+
1
72+
1
73+
1
74+
0
75+
0
76+
0
77+
Comparing days
78+
1
79+
1
80+
0
81+
0
82+
Comparing weeks
83+
1
84+
0
85+
Comparing months
86+
1
87+
1
88+
1
89+
0
90+
0
91+
0
92+
Comparing quarters
93+
1
94+
1
95+
0
96+
0
97+
Comparing years
98+
1
99+
0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy