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

coprocessor/dag:fix bug caused by use offset in expr #2064

Merged
merged 22 commits into from Jul 28, 2017

Conversation

AndreMouche
Copy link
Member

Hi,
This PR will fix bug caused by use column_id instead of column_offset in expression.
And its tests in test_select is not finished.
@hanfei1991 you can test it first.

@@ -35,27 +35,23 @@ pub struct AggregationExecutor<'a> {
cursor: usize,
executed: bool,
ctx: Rc<EvalContext>,
cols: Vec<ColumnInfo>,
cols: Rc<Vec<ColumnInfo>>,
related_cols: Vec<usize>, // offset of related columns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related_cols_offset or sth.?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use name consistently.

name represent
column/column_info/info Column Info
id/column_id Column ID
offset Column Offset

@choleraehyq choleraehyq changed the title coprocessor/dag:fix bug cased by use offset in expr coprocessor/dag:fix bug caused by use offset in expr Jul 24, 2017
}

pub fn visit(&mut self, expr: &Expr) -> Result<()> {
if expr.get_tp() == ExprType::ColumnRef {
self.col_ids.insert(box_try!(expr.get_val().decode_i64()));
let offset = box_try!(expr.get_val().decode_i64()) as usize;
if offset < self.cols_len {
Copy link
Contributor

@hhkbp2 hhkbp2 Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return an error if offset invalid?

@@ -53,6 +68,10 @@ impl ExprColumnRefVisitor {
}
Ok(())
}

pub fn cols(self) -> Vec<usize> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/cols/column_offsets/

use super::super::table_scan::TableScanExecutor;
use super::super::scanner::test::{TestStore, get_range, new_col_info};


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line.

@hhkbp2
Copy link
Contributor

hhkbp2 commented Jul 24, 2017

CI fails @AndreMouche

@hhkbp2
Copy link
Contributor

hhkbp2 commented Jul 24, 2017

Rest LGTM

@hhkbp2
Copy link
Contributor

hhkbp2 commented Jul 25, 2017

PTAL @hanfei1991 @XuHuaiyu @andelf

@AndreMouche
Copy link
Member Author

@hanfei1991 @hanfei19910905 PTAL

@AndreMouche
Copy link
Member Author

@hanfei1991 @andelf @BusyJay @XuHuaiyu PTAL

@andelf
Copy link
Contributor

andelf commented Jul 26, 2017

LGTM

ExprColumnRefVisitor { col_ids: HashSet::new() }
pub fn new(cols_len: usize) -> ExprColumnRefVisitor {
ExprColumnRefVisitor {
cols_offset: HashSet::default(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use with_capacity here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No associated item named with_capacity found for type std::collections::HashSet<_, std::hash::BuildHasherDefault<fnv::FnvHasher>> in the current scope @BusyJay

}

pub fn visit(&mut self, expr: &Expr) -> Result<()> {
if expr.get_tp() == ExprType::ColumnRef {
self.col_ids.insert(box_try!(expr.get_val().decode_i64()));
let offset = box_try!(expr.get_val().decode_i64()) as usize;
if offset > self.cols_len {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be >=?

@@ -27,18 +36,28 @@ pub mod aggregation;

#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed?

self.col_ids.insert(box_try!(expr.get_val().decode_i64()));
let offset = box_try!(expr.get_val().decode_i64()) as usize;
if offset > self.cols_len {
return Err(Error::Other(box_err!("offset {} overflow,should be less than {}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space.

src: Box<Executor + 'a>)
-> Result<AggregationExecutor<'a>> {
// collect all cols used in aggregation
let mut visitor = ExprColumnRefVisitor::new();
let mut visitor = ExprColumnRefVisitor::new(columns.len());
let group_by = meta.take_group_by().into_vec();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think visitor.batch_visit(meta.get_group_by()) should be ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

group_by is not only been used in visitor and would be taken later @BusyJay

src: Box<Executor + 'a>)
-> Result<SelectionExecutor<'a>> {
let conditions = meta.take_conditions().into_vec();
let mut visitor = ExprColumnRefVisitor::new();
let mut visitor = ExprColumnRefVisitor::new(columns_info.len());
for cond in &conditions {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use batch_visit?

@AndreMouche
Copy link
Member Author

@BusyJay @hhkbp2 @hanfei1991 PTAL

@@ -193,6 +197,13 @@ impl Table {
c_info.set_pk_handle(col.id == self.handle_id);
idx_info.mut_columns().push(c_info);
}
if let Some(col) = self.cols.get(&self.handle_id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

let columns_info = index_info.take_columns();
scan.set_columns(columns_info.clone());
exec.set_idx_scan(scan);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many empty lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address comment

Copy link
Member

@BusyJay BusyJay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AndreMouche AndreMouche merged commit 24edb72 into master Jul 28, 2017
@AndreMouche AndreMouche deleted the shirly/dag_offset branch July 28, 2017 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants