Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Hide detail module structure #178

Merged
merged 36 commits into from Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
89ed702
private to mod pipeline::field::field_name
kazuk Jun 9, 2022
0010b94
private pipeline::pump_model::window_operation_parameter::aggregate
kazuk Jun 9, 2022
1bc47ff
private pipeline::pump_model::window_operation_parameter::join_parameter
kazuk Jun 9, 2022
ff0b49d
private mod column_*
kazuk Jun 9, 2022
b396c4a
private mod pipeline::option::+
kazuk Jun 9, 2022
db48ce6
private mod pipeline::pipeline_graph::*
kazuk Jun 9, 2022
e813e8d
private mod pipeline::pump_model::*
kazuk Jun 9, 2022
9183e4b
private mod pipeline::relation::*
kazuk Jun 9, 2022
9110964
private mod pipeline::sink_writer_model::sink_writer_type
kazuk Jun 9, 2022
8aa9397
private mod pipeline::source_reader_model::source_reader_type
kazuk Jun 9, 2022
bc07135
simplify pub expr_resolver::ExprResolver
kazuk Jun 9, 2022
13ed909
private mod expr_resolver::expr_label
kazuk Jun 9, 2022
1ecb1ae
private mod expression::boolean_expression::*
kazuk Jun 9, 2022
f5126c8
private mod expression::*
kazuk Jun 9, 2022
4206eeb
private mod pipeline::field, pipeline::name
kazuk Jun 10, 2022
7869156
private mod pipeline::option
kazuk Jun 10, 2022
6513b5a
private mod pipeline::pipeline_graph
kazuk Jun 10, 2022
e535e8c
private mod pipeline::pipeline_version
kazuk Jun 10, 2022
2a399d1
apply to connection
kazuk Jun 10, 2022
963665c
private pipeline::pump_model
kazuk Jun 10, 2022
7fa78b9
private pipeline::relation
kazuk Jun 10, 2022
e82b645
private pipeline::sink_writer_model
kazuk Jun 10, 2022
07ac7ac
private pipeline::source_reader_model
kazuk Jun 10, 2022
89adb55
private pipeline::stream_model
kazuk Jun 10, 2022
42cf8d8
private metrics_update_by_task_execution mod
kazuk Jun 10, 2022
ffe9ade
private row_queue_metrics, window_queue_metrics
kazuk Jun 10, 2022
0cb1d3b
pub(something) -> pub
kazuk Jun 10, 2022
b9609cf
private sql_processor::sql_parser::parse_success, syntax
kazuk Jun 10, 2022
da048b1
private mod json
kazuk Jun 10, 2022
5f9b240
private mode format, source_row
kazuk Jun 10, 2022
29936bd
private sql_value, sql_convertible
kazuk Jun 10, 2022
1999788
private task::*
kazuk Jun 10, 2022
0103f3e
private all details module
kazuk Jun 10, 2022
de6c44f
add changelog
kazuk Jun 12, 2022
b4b4bbb
refactor: pub(...) into pub (for recently added objects)
laysakura Jun 12, 2022
f76704a
refactor: delete again the file deleted in #188
laysakura Jun 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,12 @@ All other sections are for end-users.
<!-- markdownlint-disable MD024 -->
## [Unreleased]

### For developpers

- Refactor : Hide detail module structure ([#177](https://github.com/SpringQL/SpringQL/pull/177))
- Make private to internal modules
- When publishing members outside the module, we recommend re-export(`pub use`) rather than `pub(crate)`

## [v0.12.0]

### Changed
Expand Down
6 changes: 3 additions & 3 deletions foreign-service/src/source.rs
@@ -1,6 +1,8 @@
// This file is part of https://github.com/SpringQL/SpringQL which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details.

pub mod source_input;
mod source_input;

pub use source_input::ForeignSourceInput;

use std::{
io::Write,
Expand All @@ -11,8 +13,6 @@ use std::{
use anyhow::Result;
use chrono::Duration;

use crate::source::source_input::ForeignSourceInput;

/// Runs as a TCP server and write(2)s foreign rows to socket.
pub struct ForeignSource {
listener: TcpListener,
Expand Down
Expand Up @@ -6,7 +6,7 @@ use std::{fs::File, path::Path};
use crate::source::source_input::timed_stream::file_type::FileType;

#[derive(Debug)]
pub(super) enum FileParser {
pub enum FileParser {
/// Fields are parsed as the following priority:
///
/// 1. number
Expand All @@ -15,7 +15,7 @@ pub(super) enum FileParser {
}

impl FileParser {
pub(super) fn new<P: AsRef<Path>>(file_type: FileType, file_path: P) -> Result<Self> {
pub fn new<P: AsRef<Path>>(file_type: FileType, file_path: P) -> Result<Self> {
match file_type {
FileType::Tsv => {
let reader = csv::ReaderBuilder::new()
Expand Down
6 changes: 3 additions & 3 deletions foreign-service/src/source/source_input/timed_stream/timer.rs
Expand Up @@ -3,15 +3,15 @@
use chrono::{DateTime, Duration, Utc};

#[derive(Eq, PartialEq, Debug)]
pub(super) struct Timer {
pub struct Timer {
real_initial_datetime: DateTime<Utc>,
elapsed: Duration,

virt_initial_datetime: DateTime<Utc>,
}

impl Timer {
pub(super) fn new(virt_initial_datetime: DateTime<Utc>) -> Self {
pub fn new(virt_initial_datetime: DateTime<Utc>) -> Self {
let real_initial_datetime = Utc::now();
let elapsed = Duration::seconds(0);
Timer {
Expand All @@ -21,7 +21,7 @@ impl Timer {
}
}

pub(super) fn virt_current_datetime(&mut self) -> DateTime<Utc> {
pub fn virt_current_datetime(&mut self) -> DateTime<Utc> {
self.update_clock();
self.virt_initial_datetime + self.elapsed
}
Expand Down
2 changes: 1 addition & 1 deletion springql-core/src/api.rs
Expand Up @@ -9,7 +9,7 @@ pub use crate::{
SpringConfig,
},
stream_engine::{
time::{duration::event_duration::SpringEventDuration, timestamp::SpringTimestamp},
time::{SpringEventDuration, SpringTimestamp},
SpringValue,
},
};
Expand Down
2 changes: 1 addition & 1 deletion springql-core/src/api/error.rs
Expand Up @@ -6,7 +6,7 @@ pub mod foreign_info;

use thiserror::Error;

use crate::{api::error::foreign_info::ForeignInfo, pipeline::name::StreamName};
use crate::{api::error::foreign_info::ForeignInfo, pipeline::StreamName};

/// Result type
pub type Result<T> = std::result::Result<T, SpringError>;
Expand Down
4 changes: 2 additions & 2 deletions springql-core/src/connection.rs
Expand Up @@ -4,7 +4,7 @@ use std::{sync::Once, thread, time::Duration};

use crate::{
api::{error::Result, SpringConfig},
pipeline::name::QueueName,
pipeline::QueueName,
sql_processor::SqlProcessor,
stream_engine::{command::Command, EngineMutex, Row},
};
Expand All @@ -26,7 +26,7 @@ fn setup_logger() {
/// 1 stream pipeline has only 1 connection.
/// In other words, the lifecycle of Connection and internal stream pipeline are the same.
#[derive(Debug)]
pub(crate) struct Connection {
pub struct Connection {
engine: EngineMutex,
sql_processor: SqlProcessor,
}
Expand Down
32 changes: 14 additions & 18 deletions springql-core/src/expr_resolver.rs
@@ -1,17 +1,17 @@
// This file is part of https://github.com/SpringQL/SpringQL which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details.

pub(crate) mod expr_label;
mod expr_label;
pub use expr_label::{AggrExprLabel, ExprLabel, ExprLabelGenerator, ValueExprLabel};

use std::collections::HashMap;

use anyhow::anyhow;

use crate::{
api::error::{Result, SpringError},
expr_resolver::expr_label::{AggrExprLabel, ExprLabel, ExprLabelGenerator, ValueExprLabel},
expression::{AggrExpr, ValueExpr},
pipeline::name::{AggrAlias, ValueAlias},
sql_processor::sql_parser::syntax::SelectFieldSyntax,
pipeline::{AggrAlias, ValueAlias},
sql_processor::SelectFieldSyntax,
stream_engine::{SqlValue, Tuple},
};

Expand All @@ -21,7 +21,7 @@ use crate::{
/// 2. resolve alias in ValueExprOrAlias / AggrExprAlias and get existing ExprLabel.
/// 3. evaluate expression into SqlValue from ExprLabel.
#[derive(Clone, PartialEq, Debug)]
pub(crate) struct ExprResolver {
pub struct ExprResolver {
label_gen: ExprLabelGenerator,

value_expressions: HashMap<ValueExprLabel, ValueExpr>,
Expand All @@ -36,7 +36,7 @@ impl ExprResolver {
/// # Returns
///
/// `(instance, value/aggr expr labels in select_list)
pub(crate) fn new(select_list: Vec<SelectFieldSyntax>) -> (Self, Vec<ExprLabel>) {
pub fn new(select_list: Vec<SelectFieldSyntax>) -> (Self, Vec<ExprLabel>) {
let mut label_gen = ExprLabelGenerator::default();
let mut value_expressions = HashMap::new();
let mut value_aliased_labels = HashMap::new();
Expand Down Expand Up @@ -81,7 +81,7 @@ impl ExprResolver {
/// # Failures
///
/// - `SpringError::Sql` if alias is not in select_list.
pub(crate) fn resolve_value_alias(&self, value_alias: ValueAlias) -> Result<ValueExprLabel> {
pub fn resolve_value_alias(&self, value_alias: ValueAlias) -> Result<ValueExprLabel> {
self.value_aliased_labels
.get(&value_alias)
.cloned()
Expand All @@ -99,7 +99,7 @@ impl ExprResolver {
///
/// - `SpringError::Sql` if alias is not in select_list.
#[allow(dead_code)]
pub(crate) fn resolve_aggr_alias(&self, aggr_alias: AggrAlias) -> Result<AggrExprLabel> {
pub fn resolve_aggr_alias(&self, aggr_alias: AggrAlias) -> Result<AggrExprLabel> {
self.aggr_aliased_labels
.get(&aggr_alias)
.cloned()
Expand All @@ -114,15 +114,15 @@ impl ExprResolver {
/// # Panics
///
/// - `label` is not found
pub(crate) fn resolve_aggr_expr(&self, label: AggrExprLabel) -> AggrExpr {
pub fn resolve_aggr_expr(&self, label: AggrExprLabel) -> AggrExpr {
self.aggr_expressions
.get(&label)
.cloned()
.unwrap_or_else(|| panic!("label {:?} not found", label))
}

/// Register value expression which is not in select_list
pub(crate) fn register_value_expr(&mut self, value_expr: ValueExpr) -> ValueExprLabel {
pub fn register_value_expr(&mut self, value_expr: ValueExpr) -> ValueExprLabel {
let label = self.label_gen.next_value();
self.value_expressions.insert(label, value_expr);
label
Expand All @@ -132,7 +132,7 @@ impl ExprResolver {
///
/// Register aggregate expression which is not in select_list
#[allow(dead_code)]
pub(crate) fn register_aggr_expr(&mut self, aggr_expr: AggrExpr) -> AggrExprLabel {
pub fn register_aggr_expr(&mut self, aggr_expr: AggrExpr) -> AggrExprLabel {
let label = self.label_gen.next_aggr();
self.aggr_expressions.insert(label, aggr_expr);
label
Expand All @@ -149,7 +149,7 @@ impl ExprResolver {
/// - `SpringError::Sql` when:
/// - column reference in expression is not found in `tuple`.
/// - somehow failed to eval expression.
pub(crate) fn eval_value_expr(&self, label: ValueExprLabel, tuple: &Tuple) -> Result<SqlValue> {
pub fn eval_value_expr(&self, label: ValueExprLabel, tuple: &Tuple) -> Result<SqlValue> {
let value_expr = self
.value_expressions
.get(&label)
Expand All @@ -173,11 +173,7 @@ impl ExprResolver {
/// - `SpringError::Sql` when:
/// - column reference in expression is not found in `tuple`.
/// - somehow failed to eval expression.
pub(crate) fn eval_aggr_expr_inner(
&self,
label: AggrExprLabel,
tuple: &Tuple,
) -> Result<SqlValue> {
pub fn eval_aggr_expr_inner(&self, label: AggrExprLabel, tuple: &Tuple) -> Result<SqlValue> {
let aggr_expr = self.resolve_aggr_expr(label);
let value_expr = aggr_expr.aggregated;
let value_expr_ph2 = value_expr.resolve_colref(tuple)?;
Expand All @@ -187,7 +183,7 @@ impl ExprResolver {

#[cfg(test)]
mod tests {
use crate::{expression::ValueExpr, stream_engine::time::timestamp::SpringTimestamp};
use crate::{expression::ValueExpr, stream_engine::time::SpringTimestamp};

use super::*;

Expand Down
12 changes: 6 additions & 6 deletions springql-core/src/expr_resolver/expr_label.rs
@@ -1,34 +1,34 @@
// This file is part of https://github.com/SpringQL/SpringQL which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details.

#[derive(Clone, Eq, PartialEq, Debug, Default)]
pub(crate) struct ExprLabelGenerator {
pub struct ExprLabelGenerator {
value: u16,
aggr: u16,
}

impl ExprLabelGenerator {
pub(crate) fn next_value(&mut self) -> ValueExprLabel {
pub fn next_value(&mut self) -> ValueExprLabel {
let label = ValueExprLabel(self.value);
self.value += 1;
label
}

pub(crate) fn next_aggr(&mut self) -> AggrExprLabel {
pub fn next_aggr(&mut self) -> AggrExprLabel {
let label = AggrExprLabel(self.aggr);
self.aggr += 1;
label
}
}

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub(crate) struct ValueExprLabel(u16);
pub struct ValueExprLabel(u16);

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub(crate) struct AggrExprLabel(u16);
pub struct AggrExprLabel(u16);

/// Either ValueExprLabel or AggrExprLabel.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub(crate) enum ExprLabel {
pub enum ExprLabel {
Value(ValueExprLabel),
Aggr(AggrExprLabel),
}
41 changes: 17 additions & 24 deletions springql-core/src/expression.rs
Expand Up @@ -2,40 +2,33 @@

#![doc = include_str!("expression.md")]

pub(crate) mod boolean_expression;
pub(crate) mod function_call;
pub(crate) mod operator;
mod boolean_expression;
mod function_call;
mod operator;

pub use boolean_expression::{BinaryExpr, ComparisonFunction, LogicalFunction, NumericalFunction};
pub use function_call::FunctionCall;
pub use operator::{BinaryOperator, UnaryOperator};

use anyhow::anyhow;

use crate::{
api::error::{Result, SpringError},
expression::{
boolean_expression::{
comparison_function::ComparisonFunction, logical_function::LogicalFunction,
numerical_function::NumericalFunction, BinaryExpr,
},
function_call::FunctionCall,
operator::UnaryOperator,
},
pipeline::{
field::field_name::ColumnReference,
pump_model::window_operation_parameter::aggregate::AggregateFunctionParameter,
},
pipeline::{AggregateFunctionParameter, ColumnReference},
stream_engine::{
time::duration::{event_duration::SpringEventDuration, SpringDuration},
time::{SpringDuration, SpringEventDuration},
NnSqlValue, SqlCompareResult, SqlValue, Tuple,
},
};

pub(crate) trait ValueExprType {}
pub trait ValueExprType {}

/// Value Expression.
///
/// A value expression can be evaluated into SqlValue with a tuple (to resolve column reference).
/// ValueExpr may contain column references to resolve from a row.
#[derive(Clone, PartialEq, Hash, Debug)]
pub(crate) enum ValueExpr {
pub enum ValueExpr {
Constant(SqlValue),
UnaryOperator(UnaryOperator, Box<Self>),
BinaryExpr(BinaryExpr<Self>),
Expand All @@ -46,7 +39,7 @@ pub(crate) enum ValueExpr {
impl ValueExprType for ValueExpr {}

impl ValueExpr {
pub(crate) fn resolve_colref(self, tuple: &Tuple) -> Result<ValueExprPh2> {
pub fn resolve_colref(self, tuple: &Tuple) -> Result<ValueExprPh2> {
match self {
Self::Constant(value) => Ok(ValueExprPh2::Constant(value)),

Expand Down Expand Up @@ -147,7 +140,7 @@ impl ValueExpr {
///
/// A value expression phase2 can be evaluated by itself.
#[derive(Clone, PartialEq, Hash, Debug)]
pub(crate) enum ValueExprPh2 {
pub enum ValueExprPh2 {
Constant(SqlValue),
UnaryOperator(UnaryOperator, Box<Self>),
BinaryExpr(BinaryExpr<Self>),
Expand All @@ -156,7 +149,7 @@ pub(crate) enum ValueExprPh2 {
impl ValueExprType for ValueExprPh2 {}

impl ValueExprPh2 {
pub(crate) fn eval(self) -> Result<SqlValue> {
pub fn eval(self) -> Result<SqlValue> {
match self {
Self::Constant(sql_value) => Ok(sql_value),
Self::UnaryOperator(uni_op, child) => {
Expand Down Expand Up @@ -280,7 +273,7 @@ impl ValueExprPh2 {

/// Aggregate expression.
#[derive(Clone, PartialEq, Debug)]
pub(crate) struct AggrExpr {
pub(crate) func: AggregateFunctionParameter,
pub(crate) aggregated: ValueExpr,
pub struct AggrExpr {
pub func: AggregateFunctionParameter,
pub aggregated: ValueExpr,
}
20 changes: 9 additions & 11 deletions springql-core/src/expression/boolean_expression.rs
@@ -1,21 +1,19 @@
// This file is part of https://github.com/SpringQL/SpringQL which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details.

pub(crate) mod comparison_function;
pub(crate) mod logical_function;
pub(crate) mod numerical_function;
mod comparison_function;
mod logical_function;
mod numerical_function;

use crate::expression::{
boolean_expression::{
comparison_function::ComparisonFunction, logical_function::LogicalFunction,
numerical_function::NumericalFunction,
},
ValueExprType,
};
pub use comparison_function::ComparisonFunction;
pub use logical_function::LogicalFunction;
pub use numerical_function::NumericalFunction;

use crate::expression::ValueExprType;

/// Boolean expression.
#[allow(clippy::enum_variant_names)]
#[derive(Clone, PartialEq, Hash, Debug)]
pub(crate) enum BinaryExpr<E>
pub enum BinaryExpr<E>
where
E: ValueExprType,
{
Expand Down
Expand Up @@ -4,7 +4,7 @@ use crate::expression::ValueExprType;

/// Comparison function and its operands
#[derive(Clone, PartialEq, Hash, Debug)]
pub(crate) enum ComparisonFunction<E>
pub enum ComparisonFunction<E>
where
E: ValueExprType,
{
Expand Down