text
stringlengths
70
351k
source
stringclasses
4 values
// file: hyperswitch/crates/analytics/src/sqlx.rs | crate: analytics use std::{fmt::Display, str::FromStr}; use common_utils::{ errors::{CustomResult, ParsingError}, DbConnectionParams, }; use sqlx::{ postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef}, Decode, Encode, Error::ColumnNotFound, FromRow, Pool, Postgres, Row, }; use super::{ health_check::HealthCheck, query::{Aggregate, ToSql, Window}, types::{ AnalyticsCollection, AnalyticsDataSource, DBEnumWrapper, LoadRow, QueryExecutionError, TableEngine, }, }; async fn load_results<T>(&self, query: &str) -> CustomResult<Vec<T>, QueryExecutionError> where Self: LoadRow<T>, { sqlx::query(&format!("{query};")) .fetch_all(&self.pool) .await .change_context(QueryExecutionError::DatabaseError) .attach_printable_lazy(|| format!("Failed to run query {query}"))? .into_iter() .map(Self::load_row) .collect::<Result<Vec<_>, _>>() .change_context(QueryExecutionError::RowExtractionFailure) }
ast_fragments
// file: hyperswitch/crates/analytics/src/sqlx.rs | crate: analytics use common_utils::{ errors::{CustomResult, ParsingError}, DbConnectionParams, }; use sqlx::{ postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef}, Decode, Encode, Error::ColumnNotFound, FromRow, Pool, Postgres, Row, }; use super::{ health_check::HealthCheck, query::{Aggregate, ToSql, Window}, types::{ AnalyticsCollection, AnalyticsDataSource, DBEnumWrapper, LoadRow, QueryExecutionError, TableEngine, }, }; fn load_row(row: PgRow) -> CustomResult<T, QueryExecutionError> { T::from_row(&row).change_context(QueryExecutionError::RowExtractionFailure) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/sqlx.rs | crate: analytics use sqlx::{ postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef}, Decode, Encode, Error::ColumnNotFound, FromRow, Pool, Postgres, Row, }; fn type_info() -> PgTypeInfo { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/sqlx.rs | crate: analytics use std::{fmt::Display, str::FromStr}; use sqlx::{ postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef}, Decode, Encode, Error::ColumnNotFound, FromRow, Pool, Postgres, Row, }; use super::{ health_check::HealthCheck, query::{Aggregate, ToSql, Window}, types::{ AnalyticsCollection, AnalyticsDataSource, DBEnumWrapper, LoadRow, QueryExecutionError, TableEngine, }, }; fn decode( value: PgValueRef<'r>, ) -> Result<Self, Box<dyn std::error::Error + 'static + Send + Sync>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/sqlx.rs | crate: analytics use sqlx::{ postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef}, Decode, Encode, Error::ColumnNotFound, FromRow, Pool, Postgres, Row, }; fn size_hint(&self) -> usize { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/sqlx.rs | crate: analytics use std::{fmt::Display, str::FromStr}; use sqlx::{ postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef}, Decode, Encode, Error::ColumnNotFound, FromRow, Pool, Postgres, Row, }; fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<sqlx::encode::IsNull, Box<(dyn std::error::Error + Send + Sync + 'static)>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/analytics/src/sqlx.rs | crate: analytics use std::{fmt::Display, str::FromStr}; use sqlx::{ postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef}, Decode, Encode, Error::ColumnNotFound, FromRow, Pool, Postgres, Row, }; use storage_impl::config::Database; use time::PrimitiveDateTime; pub async fn from_conf(conf: &Database, schema: &str) -> Self { let database_url = conf.get_database_url(schema); #[allow(clippy::expect_used)] let pool = PgPoolOptions::new() .max_connections(conf.pool_size) .acquire_timeout(std::time::Duration::from_secs(conf.connection_timeout)) .connect_lazy(&database_url) .expect("SQLX Pool Creation failed"); Self { pool } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/sqlx.rs | crate: analytics use diesel_models::enums::{ AttemptStatus, AuthenticationType, Currency, FraudCheckStatus, IntentStatus, PaymentMethod, RefundStatus, }; use sqlx::{ postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef}, Decode, Encode, Error::ColumnNotFound, FromRow, Pool, Postgres, Row, }; use time::PrimitiveDateTime; use super::{ health_check::HealthCheck, query::{Aggregate, ToSql, Window}, types::{ AnalyticsCollection, AnalyticsDataSource, DBEnumWrapper, LoadRow, QueryExecutionError, TableEngine, }, }; fn from_row(row: &'a PgRow) -> sqlx::Result<Self> { {let currency: Option<DBEnumWrapper<Currency>> = row.try_get("currency").or_else(|e| match e { ColumnNotFound(_) => Ok(Default::default()), e => Err(e), })?;<|fim_suffix|> <|fim_middle|> Ok(Self { currency, status, connector, authentication_type, payment_method, payment_method_type, client_source, client_version, profile_id, card_network, merchant_id, card_last_4, card_issuer, error_reason, first_attempt, total, count, error_message, start_bucket, end_bucket, })}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use error_stack::{report, Report, ResultExt}; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn to_sql(&self, table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> { { Self::Sum { field, partition_by, order_by, alias, } => { format!( "sum({}) over ({}{}){}", field .to_sql(table_engine) .attach_printable("Failed to sum window")?, partition_by.as_ref().map_or_else( || "".to_owned(), |partition_by| format!("partition by {}", partition_by.to_owned()) ), order_by.as_ref().map_or_else( || "".to_owned(), |(order_column, order)| format!( " order by {} {}", order_column.to_owned(), order ) ), alias.map_or_else(|| "".to_owned(), |alias| format!(" as {}", alias)) ) }<|fim_suffix|> <|fim_middle|> Self::RowNumber { field: _, partition_by, order_by, alias, } => { format!( "row_number() over ({}{}){}", partition_by.as_ref().map_or_else( || "".to_owned(), |partition_by| format!("partition by {}", partition_by.to_owned()) ), order_by.as_ref().map_or_else( || "".to_owned(), |(order_column, order)| format!( " order by {} {}", order_column.to_owned(), order ) ), alias.map_or_else(|| "".to_owned(), |alias| format!(" as {}", alias)) ) } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use error_stack::{report, Report, ResultExt}; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn to_sql(&self, table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use actix_web::http::StatusCode; use error_stack::{report, Report, ResultExt}; use router_env::logger; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; async fn execute_query(&self, query: &str) -> ClickhouseResult<Vec<serde_json::Value>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics Self::Dispute => Ok("dispute".to_string()), Self::DisputeSessionized => Ok("sessionizer_dispute".to_string()), Self::ActivePaymentsAnalytics => Ok("active_payments".to_string()), Self::Authentications => Ok("authentications".to_string()), } } } impl<T> ToSql<ClickhouseClient> for Aggregate<T> where T: ToSql<ClickhouseClient>, { fn to_sql(&self, table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> { Ok(match self { Self::Count { field: _, alias } => { let query = match table_engine { TableEngine::CollapsingMergeTree { sign } => format!("sum({sign})"), TableEngine::BasicTree => "count(*)".to_string(), }; format!( "{query}{}", alias.map_or_else(|| "".to_owned(), |alias| format!(" as {}", alias)) ) } Self::Sum { field, alias } => { fn to_sql(&self, table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> { { TableEngine::CollapsingMergeTree { sign } => format!( "sum({sign} * {})", field .to_sql(table_engine) .attach_printable("Failed to sum aggregate")? ),<|fim_suffix|> <|fim_middle|> TableEngine::BasicTree => format!( "sum({})", field .to_sql(table_engine) .attach_printable("Failed to sum aggregate")? ), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<SdkEventMetricRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use error_stack::{report, Report, ResultExt}; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn to_sql(&self, _table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<ActivePaymentsMetricRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<OutgoingWebhookLogsResult, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<ApiEventFilter, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<AuthEventFilterRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<AuthEventMetricRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<SdkEventFilter, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<SdkEventMetricRow, Self::Error> { serde_json::from_value(self).change_context(ParsingError::StructParseFailure( "Failed to parse SdkEventMetricRow in clickhouse results", )) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<LatencyAvg, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<ApiEventMetricRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<DisputeFilterRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<DisputeMetricRow, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<FrmFilterRow, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<FrmMetricRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<RefundDistributionRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<RefundFilterRow, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<RefundMetricRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<PaymentIntentFilterRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<PaymentIntentMetricRow, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<PaymentFilterRow, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<PaymentDistributionRow, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<PaymentMetricRow, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<ConnectorEventsResult, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<SdkEventsResult, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn try_into(self) -> Result<ApiLogsResult, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; fn load_row(row: Self::Row) -> common_utils::errors::CustomResult<T, QueryExecutionError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; use crate::{ api_event::{ events::ApiLogsResult, filters::ApiEventFilter, metrics::{latency::LatencyAvg, ApiEventMetricRow}, }, auth_events::filters::AuthEventFilterRow, connector_events::events::ConnectorEventsResult, disputes::{filters::DisputeFilterRow, metrics::DisputeMetricRow}, outgoing_webhook_event::events::OutgoingWebhookLogsResult, sdk_events::events::SdkEventsResult, types::TableEngine, }; fn get_table_engine(table: AnalyticsCollection) -> TableEngine { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>; async fn load_results<T>( &self, query: &str, ) -> common_utils::errors::CustomResult<Vec<T>, QueryExecutionError> where Self: LoadRow<T>, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/analytics/src/clickhouse.rs | crate: analytics use common_utils::errors::ParsingError; use super::{ active_payments::metrics::ActivePaymentsMetricRow, auth_events::metrics::AuthEventMetricRow, frm::{filters::FrmFilterRow, metrics::FrmMetricRow}, health_check::HealthCheck, payment_intents::{filters::PaymentIntentFilterRow, metrics::PaymentIntentMetricRow}, payments::{ distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow, }, query::{Aggregate, ToSql, Window}, refunds::{ distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow, }, sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow}, types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError}, }; async fn deep_health_check( &self, ) -> common_utils::errors::CustomResult<(), QueryExecutionError> { self.execute_query("SELECT 1") .await .map(|_| ()) .change_context(QueryExecutionError::DatabaseError) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics pub use types::AnalyticsDomain; use std::{collections::HashSet, sync::Arc}; use clickhouse::ClickhouseClient; pub use clickhouse::ClickhouseConfig; use storage_impl::config::Database; use self::{ active_payments::metrics::{ActivePaymentsMetric, ActivePaymentsMetricRow}, auth_events::metrics::{AuthEventMetric, AuthEventMetricRow}, frm::metrics::{FrmMetric, FrmMetricRow}, payment_intents::metrics::{PaymentIntentMetric, PaymentIntentMetricRow}, payments::{ distribution::{PaymentDistribution, PaymentDistributionRow}, metrics::{PaymentMetric, PaymentMetricRow}, }, refunds::metrics::{RefundMetric, RefundMetricRow}, sdk_events::metrics::{SdkEventMetric, SdkEventMetricRow}, sqlx::SqlxClient, types::MetricsError, }; pub async fn from_conf( config: &AnalyticsConfig, tenant: &dyn storage_impl::config::TenantConfig, ) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics dimensions, filters, granularity, // Since API events are ckh only use ckh here time_range, ckh_pool, ) .await } } } pub async fn get_api_event_metrics( &self, metric: &ApiEventMetrics, dimensions: &[ApiEventDimensions], merchant_id: &common_utils::id_type::MerchantId, filters: &ApiEventFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(ApiEventMetricsBucketIdentifier, ApiEventMetricRow)>> { match self { Self::Sqlx(_pool) => Err(report!(MetricsError::NotImplemented)), Self::Clickhouse(ckh_pool) | Self::CombinedCkh(_, ckh_pool) pub async fn get_api_event_metrics( &self, metric: &ApiEventMetrics, dimensions: &[ApiEventDimensions], merchant_id: &common_utils::id_type::MerchantId, filters: &ApiEventFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(ApiEventMetricsBucketIdentifier, ApiEventMetricRow)>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics metric .load_metrics(merchant_id, publishable_key, time_range, pool) .await } Self::CombinedCkh(_sqlx_pool, ckh_pool) | Self::CombinedSqlx(_sqlx_pool, ckh_pool) => { metric .load_metrics(merchant_id, publishable_key, time_range, ckh_pool) .await } } } pub async fn get_auth_event_metrics( &self, metric: &AuthEventMetrics, dimensions: &[AuthEventDimensions], merchant_id: &common_utils::id_type::MerchantId, filters: &AuthEventFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(AuthEventMetricsBucketIdentifier, AuthEventMetricRow)>> { match self { Self::Sqlx(_pool) => Err(report!(MetricsError::NotImplemented)), Self::Clickhouse(pool) => { metric pub async fn get_auth_event_metrics( &self, metric: &AuthEventMetrics, dimensions: &[AuthEventDimensions], merchant_id: &common_utils::id_type::MerchantId, filters: &AuthEventFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(AuthEventMetricsBucketIdentifier, AuthEventMetricRow)>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics publishable_key, filters, granularity, // Since SDK events are ckh only use ckh here time_range, ckh_pool, ) .await } } } pub async fn get_active_payments_metrics( &self, metric: &ActivePaymentsMetrics, merchant_id: &common_utils::id_type::MerchantId, publishable_key: &str, time_range: &TimeRange, ) -> types::MetricsResult< HashSet<( ActivePaymentsMetricsBucketIdentifier, ActivePaymentsMetricRow, )>, > { match self { pub async fn get_active_payments_metrics( &self, metric: &ActivePaymentsMetrics, merchant_id: &common_utils::id_type::MerchantId, publishable_key: &str, time_range: &TimeRange, ) -> types::MetricsResult< HashSet<( ActivePaymentsMetricsBucketIdentifier, ActivePaymentsMetricRow, )>, > { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics }; sqlx_result } } }, &metrics::METRIC_FETCH_TIME, metric, self, ) .await } pub async fn get_sdk_event_metrics( &self, metric: &SdkEventMetrics, dimensions: &[SdkEventDimensions], publishable_key: &str, filters: &SdkEventFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(SdkEventMetricsBucketIdentifier, SdkEventMetricRow)>> { match self { Self::Sqlx(_pool) => Err(report!(MetricsError::NotImplemented)), Self::Clickhouse(pool) => { metric pub async fn get_sdk_event_metrics( &self, metric: &SdkEventMetrics, dimensions: &[SdkEventDimensions], publishable_key: &str, filters: &SdkEventFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(SdkEventMetricsBucketIdentifier, SdkEventMetricRow)>> { match self { Self::Sqlx(_pool) => Err(report!(MetricsError::NotImplemented)), Self::Clickhouse(pool) => { metric .load_metrics( dimensions, publishable_key, filters, granularity, time_range, pool, ) .await } Self::CombinedCkh(_sqlx_pool, ckh_pool) | Self::CombinedSqlx(_sqlx_pool, ckh_pool) => { metric .load_metrics( dimensions, publishable_key, filters, granularity, // Since SDK events are ckh only use ckh here time_range, ckh_pool, ) .await } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics pub use types::AnalyticsDomain; use std::{collections::HashSet, sync::Arc}; use clickhouse::ClickhouseClient; pub use clickhouse::ClickhouseConfig; use storage_impl::config::Database; use self::{ active_payments::metrics::{ActivePaymentsMetric, ActivePaymentsMetricRow}, auth_events::metrics::{AuthEventMetric, AuthEventMetricRow}, frm::metrics::{FrmMetric, FrmMetricRow}, payment_intents::metrics::{PaymentIntentMetric, PaymentIntentMetricRow}, payments::{ distribution::{PaymentDistribution, PaymentDistributionRow}, metrics::{PaymentMetric, PaymentMetricRow}, }, refunds::metrics::{RefundMetric, RefundMetricRow}, sdk_events::metrics::{SdkEventMetric, SdkEventMetricRow}, sqlx::SqlxClient, types::MetricsError, }; pub async fn from_conf( config: &AnalyticsConfig, tenant: &dyn storage_impl::config::TenantConfig, ) -> Self { { AnalyticsConfig::Sqlx { sqlx, .. } => { Self::Sqlx(SqlxClient::from_conf(sqlx, tenant.get_schema()).await) }<|fim_suffix|> <|fim_middle|> AnalyticsConfig::CombinedSqlx { sqlx, clickhouse, .. } => Self::CombinedSqlx( SqlxClient::from_conf(sqlx, tenant.get_schema()).await, ClickhouseClient { config: Arc::new(clickhouse.clone()), database: tenant.get_clickhouse_database().to_string(), }, ), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics publishable_key, filters, granularity, // Since SDK events are ckh only use ckh here time_range, ckh_pool, ) .await } } } pub async fn get_active_payments_metrics( &self, metric: &ActivePaymentsMetrics, merchant_id: &common_utils::id_type::MerchantId, publishable_key: &str, time_range: &TimeRange, ) -> types::MetricsResult< HashSet<( ActivePaymentsMetricsBucketIdentifier, ActivePaymentsMetricRow, )>, > { match self { pub async fn get_active_payments_metrics( &self, metric: &ActivePaymentsMetrics, merchant_id: &common_utils::id_type::MerchantId, publishable_key: &str, time_range: &TimeRange, ) -> types::MetricsResult< HashSet<( ActivePaymentsMetricsBucketIdentifier, ActivePaymentsMetricRow, )>, > { { Self::Sqlx(_pool) => Err(report!(MetricsError::NotImplemented)),<|fim_suffix|> <|fim_middle|> Self::CombinedCkh(_sqlx_pool, ckh_pool) | Self::CombinedSqlx(_sqlx_pool, ckh_pool) => { metric .load_metrics(merchant_id, publishable_key, time_range, ckh_pool) .await } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics pub use types::AnalyticsDomain; pub use clickhouse::ClickhouseConfig; use router_env::{ logger, tracing::{self, instrument}, types::FlowMetric, }; use self::{ active_payments::metrics::{ActivePaymentsMetric, ActivePaymentsMetricRow}, auth_events::metrics::{AuthEventMetric, AuthEventMetricRow}, frm::metrics::{FrmMetric, FrmMetricRow}, payment_intents::metrics::{PaymentIntentMetric, PaymentIntentMetricRow}, payments::{ distribution::{PaymentDistribution, PaymentDistributionRow}, metrics::{PaymentMetric, PaymentMetricRow}, }, refunds::metrics::{RefundMetric, RefundMetricRow}, sdk_events::metrics::{SdkEventMetric, SdkEventMetricRow}, sqlx::SqlxClient, types::MetricsError, }; pub fn get_forex_enabled(&self) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics use std::{collections::HashSet, sync::Arc}; use router_env::{ logger, tracing::{self, instrument}, types::FlowMetric, }; use self::{ active_payments::metrics::{ActivePaymentsMetric, ActivePaymentsMetricRow}, auth_events::metrics::{AuthEventMetric, AuthEventMetricRow}, frm::metrics::{FrmMetric, FrmMetricRow}, payment_intents::metrics::{PaymentIntentMetric, PaymentIntentMetricRow}, payments::{ distribution::{PaymentDistribution, PaymentDistributionRow}, metrics::{PaymentMetric, PaymentMetricRow}, }, refunds::metrics::{RefundMetric, RefundMetricRow}, sdk_events::metrics::{SdkEventMetric, SdkEventMetricRow}, sqlx::SqlxClient, types::MetricsError, }; fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { { Self::Clickhouse(_) => "Clickhouse",<|fim_suffix|> <|fim_middle|> Self::CombinedSqlx(_, _) => "CombinedSqlx", } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics }; sqlx_result } } }, &metrics::METRIC_FETCH_TIME, metric, self, ) .await } pub async fn get_dispute_metrics( &self, metric: &DisputeMetrics, dimensions: &[DisputeDimensions], auth: &AuthInfo, filters: &DisputeFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(DisputeMetricsBucketIdentifier, DisputeMetricRow)>> { // Metrics to get the fetch time for each refund metric metrics::request::record_operation_time( async { match self { pub async fn get_dispute_metrics( &self, metric: &DisputeMetrics, dimensions: &[DisputeDimensions], auth: &AuthInfo, filters: &DisputeFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(DisputeMetricsBucketIdentifier, DisputeMetricRow)>> { { (Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => { logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres disputes analytics metrics") }<|fim_suffix|> <|fim_middle|> _ => {} } }
ast_fragments
// file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics sqlx_result } } }, &metrics::METRIC_FETCH_TIME, &distribution.distribution_for, self, ) .await } pub async fn get_frm_metrics( &self, metric: &FrmMetrics, dimensions: &[FrmDimensions], merchant_id: &common_utils::id_type::MerchantId, filters: &FrmFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<Vec<(FrmMetricsBucketIdentifier, FrmMetricRow)>> { // Metrics to get the fetch time for each refund metric metrics::request::record_operation_time( async { match self { pub async fn get_frm_metrics( &self, metric: &FrmMetrics, dimensions: &[FrmDimensions], merchant_id: &common_utils::id_type::MerchantId, filters: &FrmFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<Vec<(FrmMetricsBucketIdentifier, FrmMetricRow)>> { // Metrics to get the fetch time for each refund metric metrics::request::record_operation_time( async { match self { Self::Sqlx(pool) => { metric .load_metrics( dimensions, merchant_id, filters, granularity, time_range, pool, ) .await } Self::Clickhouse(pool) => { metric .load_metrics( dimensions, merchant_id, filters, granularity, time_range, pool, ) .await } Self::CombinedCkh(sqlx_pool, ckh_pool) => { let (ckh_result, sqlx_result) = tokio::join!( metric.load_metrics( dimensions, merchant_id, filters, granularity, time_range, ckh_pool, ), metric.load_metrics( dimensions, merchant_id, filters, granularity, time_range, sqlx_pool, ) ); match (&sqlx_result, &ckh_result) { (Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => { logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres frm analytics metrics") } _ => {} }; ckh_result } Self::CombinedSqlx(sqlx_pool, ckh_pool) => { let (ckh_result, sqlx_result) = tokio::join!( metric.load_metrics( dimensions, merchant_id, filters, granularity, time_range, ckh_pool, ), metric.load_metrics( dimensions, merchant_id, filters, granularity, time_range, sqlx_pool, ) ); match (&sqlx_result, &ckh_result) { (Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => { logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres frm analytics metrics") } _ => {} }; sqlx_result } } }, &metrics::METRIC_FETCH_TIME, metric, self, ) .await }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics }; sqlx_result } } }, &metrics::METRIC_FETCH_TIME, metric, self, ) .await } pub async fn get_refund_distribution( &self, distribution: &RefundDistributionBody, dimensions: &[RefundDimensions], auth: &AuthInfo, filters: &RefundFilters, granularity: &Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<Vec<(RefundMetricsBucketIdentifier, RefundDistributionRow)>> { // Metrics to get the fetch time for each payment metric metrics::request::record_operation_time( async { match self { pub async fn get_refund_distribution( &self, distribution: &RefundDistributionBody, dimensions: &[RefundDimensions], auth: &AuthInfo, filters: &RefundFilters, granularity: &Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<Vec<(RefundMetricsBucketIdentifier, RefundDistributionRow)>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics sqlx_result } } }, &metrics::METRIC_FETCH_TIME, metric, self, ) .await } pub async fn get_refund_metrics( &self, metric: &RefundMetrics, dimensions: &[RefundDimensions], auth: &AuthInfo, filters: &RefundFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(RefundMetricsBucketIdentifier, RefundMetricRow)>> { // Metrics to get the fetch time for each refund metric metrics::request::record_operation_time( async { match self { pub async fn get_refund_metrics( &self, metric: &RefundMetrics, dimensions: &[RefundDimensions], auth: &AuthInfo, filters: &RefundFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(RefundMetricsBucketIdentifier, RefundMetricRow)>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics sqlx_result } } }, &metrics::METRIC_FETCH_TIME, &distribution.distribution_for, self, ) .await } pub async fn get_payment_intent_metrics( &self, metric: &PaymentIntentMetrics, dimensions: &[PaymentIntentDimensions], auth: &AuthInfo, filters: &PaymentIntentFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(PaymentIntentMetricsBucketIdentifier, PaymentIntentMetricRow)>> { // Metrics to get the fetch time for each payment intent metric metrics::request::record_operation_time( async { pub async fn get_payment_intent_metrics( &self, metric: &PaymentIntentMetrics, dimensions: &[PaymentIntentDimensions], auth: &AuthInfo, filters: &PaymentIntentFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(PaymentIntentMetricsBucketIdentifier, PaymentIntentMetricRow)>> { { (Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => { router_env::logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres payment intents analytics metrics") },<|fim_suffix|> <|fim_middle|> _ => {} } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics sqlx_result } } }, &metrics::METRIC_FETCH_TIME, metric, self, ) .await } pub async fn get_payment_distribution( &self, distribution: &PaymentDistributionBody, dimensions: &[PaymentDimensions], auth: &AuthInfo, filters: &PaymentFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<Vec<(PaymentMetricsBucketIdentifier, PaymentDistributionRow)>> { // Metrics to get the fetch time for each payment metric metrics::request::record_operation_time( async { match self { pub async fn get_payment_distribution( &self, distribution: &PaymentDistributionBody, dimensions: &[PaymentDimensions], auth: &AuthInfo, filters: &PaymentFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<Vec<(PaymentMetricsBucketIdentifier, PaymentDistributionRow)>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/lib.rs | crate: analytics Self::Clickhouse(_) => "Clickhouse", Self::Sqlx(_) => "Sqlx", Self::CombinedCkh(_, _) => "CombinedCkh", Self::CombinedSqlx(_, _) => "CombinedSqlx", }; write!(f, "{}", analytics_provider) } } impl AnalyticsProvider { #[instrument(skip_all)] pub async fn get_payment_metrics( &self, metric: &PaymentMetrics, dimensions: &[PaymentDimensions], auth: &AuthInfo, filters: &PaymentFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(PaymentMetricsBucketIdentifier, PaymentMetricRow)>> { // Metrics to get the fetch time for each payment metric metrics::request::record_operation_time( async { match self { pub async fn get_payment_metrics( &self, metric: &PaymentMetrics, dimensions: &[PaymentDimensions], auth: &AuthInfo, filters: &PaymentFilters, granularity: Option<Granularity>, time_range: &TimeRange, ) -> types::MetricsResult<HashSet<(PaymentMetricsBucketIdentifier, PaymentMetricRow)>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_top_n_clause( &mut self, columns: &[impl ToSql<T>], count: u64, order_column: impl ToSql<T>, order: Order, ) -> QueryResult<()> where Window<&'static str>: ToSql<T>, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use error_stack::ResultExt; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; fn clip_to_end( &self, value: Self::SeriesType, ) -> error_stack::Result<Self::SeriesType, PostProcessingError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use super::types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, TableEngine}; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; fn set_group_by_clause( &self, builder: &mut QueryBuilder<super::SqlxClient>, ) -> QueryResult<()> { let trunc_scale = self.get_lowest_common_granularity_level(); let granularity_bucket_scale = match self { Self::OneMin => None, Self::FiveMin | Self::FifteenMin | Self::ThirtyMin => Some("minute"), Self::OneHour | Self::OneDay => None, }; let granularity_divisor = self.get_bucket_size(); builder .add_group_by_clause(format!("DATE_TRUNC('{trunc_scale}', created_at)")) .attach_printable("Error adding time prune group by")?; if let Some(scale) = granularity_bucket_scale { builder .add_group_by_clause(format!( "FLOOR(DATE_PART('{scale}', created_at)/{granularity_divisor})" )) .attach_printable("Error adding time binning group by")?; } Ok(()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; fn get_select_clause(&self) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics pub fn set_limit_by(&mut self, limit: u64, columns: &[impl ToSql<T>]) -> QueryResult<()> { let columns = columns .iter() .map(|col| col.to_sql(&self.table_engine)) .collect::<Result<Vec<String>, _>>() .change_context(QueryBuildingError::SqlSerializeError) .attach_printable("Error serializing LIMIT BY columns")?; self.limit_by = Some(LimitByClause { limit, columns }); Ok(()) } pub fn add_granularity_in_mins(&mut self, granularity: Granularity) -> QueryResult<()> { let interval = match granularity { Granularity::OneMin => "1", Granularity::FiveMin => "5", Granularity::FifteenMin => "15", Granularity::ThirtyMin => "30", Granularity::OneHour => "60", Granularity::OneDay => "1440", }; let _ = self.add_select_column(format!( "toStartOfInterval(created_at, INTERVAL {interval} MINUTE) as time_bucket" )); Ok(()) pub fn add_granularity_in_mins(&mut self, granularity: Granularity) -> QueryResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use common_utils::{ errors::{CustomResult, ParsingError}, id_type::{MerchantId, OrganizationId, ProfileId}, }; use super::types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, TableEngine}; use crate::{enums::AuthInfo, types::QueryExecutionError}; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub async fn execute_query<R, P>( &mut self, store: &P, ) -> CustomResult<CustomResult<Vec<R>, QueryExecutionError>, QueryBuildingError> where P: LoadRow<R> + AnalyticsDataSource, Aggregate<&'static str>: ToSql<T>, Window<&'static str>: ToSql<T>, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn get_filter_type_clause(&self) -> Option<String> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_outer_select_column(&mut self, column: impl ToSql<T>) -> QueryResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_having_clause<R>( &mut self, aggregate: Aggregate<R>, filter_type: FilterTypes, value: impl ToSql<T>, ) -> QueryResult<()> where Aggregate<R>: ToSql<T>, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; fn get_outer_select_clause(&self) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; fn get_group_by_clause(&self) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; fn get_select_clause(&self) -> String { self.columns.join(", ") }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use diesel_models::{enums as storage_enums, enums::FraudCheckStatus}; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; fn get_filter_clause(&self) -> QueryResult<String> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use diesel_models::{enums as storage_enums, enums::FraudCheckStatus}; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_granularity_in_mins(&mut self, granularity: Granularity) -> QueryResult<()> { let interval = match granularity { Granularity::OneMin => "1", Granularity::FiveMin => "5", Granularity::FifteenMin => "15", Granularity::ThirtyMin => "30", Granularity::OneHour => "60", Granularity::OneDay => "1440", }; let _ = self.add_select_column(format!( "toStartOfInterval(created_at, INTERVAL {interval} MINUTE) as time_bucket" )); Ok(()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn set_limit_by(&mut self, limit: u64, columns: &[impl ToSql<T>]) -> QueryResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_order_by_clause( &mut self, column: impl ToSql<T>, order: impl ToSql<T>, ) -> QueryResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_group_by_clause(&mut self, column: impl ToSql<T>) -> QueryResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use common_utils::{ errors::{CustomResult, ParsingError}, id_type::{MerchantId, OrganizationId, ProfileId}, }; use error_stack::ResultExt; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_filter_in_range_clause( &mut self, key: impl ToSql<T>, values: &[impl ToSql<T>], ) -> QueryResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_nested_filter_clause(&mut self, filter: Filter) { match &mut self.filters { Filter::NestedFilter(_, ref mut filters) => filters.push(filter), f @ Filter::Plain(_, _, _) => { self.filters = Filter::NestedFilter(FilterCombinator::And, vec![f.clone(), filter]); } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_custom_filter_clause( &mut self, lhs: impl ToSql<T>, rhs: impl ToSql<T>, comparison: FilterTypes, ) -> QueryResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_negative_filter_clause( &mut self, key: impl ToSql<T>, value: impl ToSql<T>, ) -> QueryResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_bool_filter_clause( &mut self, key: impl ToSql<T>, value: impl ToSql<T>, ) -> QueryResult<()> { self.add_custom_filter_clause(key, value, FilterTypes::EqualBool) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_filter_clause( &mut self, key: impl ToSql<T>, value: impl ToSql<T>, ) -> QueryResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn set_distinct(&mut self) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use common_utils::{ errors::{CustomResult, ParsingError}, id_type::{MerchantId, OrganizationId, ProfileId}, }; use error_stack::ResultExt; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn transform_to_sql_values(&mut self, values: &[impl ToSql<T>]) -> QueryResult<String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn add_select_column(&mut self, column: impl ToSql<T>) -> QueryResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use super::types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, TableEngine}; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn new(table: AnalyticsCollection) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn filter_type_to_sql(l: &str, op: FilterTypes, r: &str) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use common_utils::{ errors::{CustomResult, ParsingError}, id_type::{MerchantId, OrganizationId, ProfileId}, }; use error_stack::ResultExt; use super::types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, TableEngine}; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; fn to_sql(&self, _table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> { let flag = *self; Ok(i8::from(flag).to_string()) }
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use common_utils::{ errors::{CustomResult, ParsingError}, id_type::{MerchantId, OrganizationId, ProfileId}, }; use error_stack::ResultExt; use super::types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, TableEngine}; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; fn to_sql(&self, _table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> { Ok(self.get_string_repr().to_owned()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use error_stack::ResultExt; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; fn clip_to_start( &self, value: Self::SeriesType, ) -> error_stack::Result<Self::SeriesType, PostProcessingError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; fn get_bucket_size(&self) -> u8 { match self { Self::OneMin => 60, Self::FiveMin => 5, Self::FifteenMin => 15, Self::ThirtyMin => 30, Self::OneHour => 60, Self::OneDay => 24, } }
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; fn get_lowest_common_granularity_level(&self) -> Self::GranularityLevel { match self { Self::OneMin => TimeGranularityLevel::Minute, Self::FiveMin | Self::FifteenMin | Self::ThirtyMin | Self::OneHour => { TimeGranularityLevel::Hour } Self::OneDay => TimeGranularityLevel::Day, } }
ast_fragments
// file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use super::types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, TableEngine}; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; fn set_group_by_clause( &self, builder: &mut QueryBuilder<super::ClickhouseClient>, ) -> QueryResult<()> { let interval = match self { Self::OneMin => "toStartOfMinute(created_at)", Self::FiveMin => "toStartOfFiveMinutes(created_at)", Self::FifteenMin => "toStartOfFifteenMinutes(created_at)", Self::ThirtyMin => "toStartOfInterval(created_at, INTERVAL 30 minute)", Self::OneHour => "toStartOfHour(created_at)", Self::OneDay => "toStartOfDay(created_at)", }; builder .add_group_by_clause(interval) .attach_printable("Error adding interval group by") }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/query.rs | crate: analytics use api_models::{ analytics::{ self as analytics_api, api_event::ApiEventDimensions, auth_events::{AuthEventDimensions, AuthEventFlows}, disputes::DisputeDimensions, frm::{FrmDimensions, FrmTransactionType}, payment_intents::PaymentIntentDimensions, payments::{PaymentDimensions, PaymentDistributions}, refunds::{RefundDimensions, RefundDistributions, RefundType}, sdk_events::{SdkEventDimensions, SdkEventNames}, Granularity, }, enums::{ AttemptStatus, AuthenticationType, Connector, Currency, DisputeStage, IntentStatus, PaymentMethod, PaymentMethodType, }, refunds::RefundStatus, }; use router_env::{logger, Flow}; use super::types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, TableEngine}; pub type QueryResult<T> = error_stack::Result<T, QueryBuildingError>; pub fn build_query(&mut self) -> QueryResult<String> where Aggregate<&'static str>: ToSql<T>, Window<&'static str>: ToSql<T>, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/opensearch.rs | crate: analytics use api_models::{ analytics::search::SearchIndex, errors::types::{ApiError, ApiErrorResponse}, }; use aws_config::{self, meta::region::RegionProviderChain, Region}; use serde_json::{json, Map, Value}; use super::{health_check::HealthCheck, query::QueryResult, types::QueryExecutionError}; use crate::{enums::AuthInfo, query::QueryBuildingError}; /// # Panics /// /// This function will panic if: /// /// * The structure of the JSON query is not as expected (e.g., missing keys or incorrect types). /// /// Ensure that the input data and the structure of the query are valid and correctly handled. pub fn construct_payload(&self, indexes: &[SearchIndex]) -> QueryResult<Vec<Value>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/opensearch.rs | crate: analytics use aws_config::{self, meta::region::RegionProviderChain, Region}; use serde_json::{json, Map, Value}; use crate::{enums::AuthInfo, query::QueryBuildingError}; pub fn build_auth_array(&self) -> Vec<Value> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/opensearch.rs | crate: analytics use api_models::{ analytics::search::SearchIndex, errors::types::{ApiError, ApiErrorResponse}, }; use aws_config::{self, meta::region::RegionProviderChain, Region}; use serde_json::{json, Map, Value}; use super::{health_check::HealthCheck, query::QueryResult, types::QueryExecutionError}; use crate::{enums::AuthInfo, query::QueryBuildingError}; pub fn build_case_insensitive_filters( &self, mut payload: Value, case_insensitive_filters: &[&(String, Vec<Value>)], auth_array: Vec<Value>, index: SearchIndex, ) -> Value { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/opensearch.rs | crate: analytics use api_models::{ analytics::search::SearchIndex, errors::types::{ApiError, ApiErrorResponse}, }; use aws_config::{self, meta::region::RegionProviderChain, Region}; use serde_json::{json, Map, Value}; use super::{health_check::HealthCheck, query::QueryResult, types::QueryExecutionError}; use crate::{enums::AuthInfo, query::QueryBuildingError}; pub fn build_filter_array( &self, case_sensitive_filters: Vec<&(String, Vec<Value>)>, index: SearchIndex, ) -> Vec<Value> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/opensearch.rs | crate: analytics use api_models::{ analytics::search::SearchIndex, errors::types::{ApiError, ApiErrorResponse}, }; use aws_config::{self, meta::region::RegionProviderChain, Region}; use common_utils::{ errors::{CustomResult, ErrorSwitch}, types::TimeRange, }; use opensearch::{ auth::Credentials, cert::CertificateValidation, cluster::{Cluster, ClusterHealthParts}, http::{ request::JsonBody, response::Response, transport::{SingleNodeConnectionPool, Transport, TransportBuilder}, Url, }, MsearchParts, OpenSearch, SearchParts, }; use serde_json::{json, Map, Value}; use crate::{enums::AuthInfo, query::QueryBuildingError}; pub async fn execute( &self, query_builder: OpenSearchQueryBuilder, ) -> CustomResult<Response, OpenSearchError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/opensearch.rs | crate: analytics use aws_config::{self, meta::region::RegionProviderChain, Region}; use common_utils::{ errors::{CustomResult, ErrorSwitch}, types::TimeRange, }; use opensearch::{ auth::Credentials, cert::CertificateValidation, cluster::{Cluster, ClusterHealthParts}, http::{ request::JsonBody, response::Response, transport::{SingleNodeConnectionPool, Transport, TransportBuilder}, Url, }, MsearchParts, OpenSearch, SearchParts, }; pub async fn create(conf: &OpenSearchConfig) -> CustomResult<Self, OpenSearchError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/analytics/src/opensearch.rs | crate: analytics use api_models::{ analytics::search::SearchIndex, errors::types::{ApiError, ApiErrorResponse}, }; use aws_config::{self, meta::region::RegionProviderChain, Region}; pub fn get_amount_field(&self, index: SearchIndex) -> &str { { SearchIndex::Refunds | SearchIndex::SessionizerRefunds => "refund_amount",<|fim_suffix|> <|fim_middle|> _ => "amount", } }
ast_fragments