fn handle_distinct(
        &self,
        itr: &mut MergeIteartor<S>,
        distinct: &parser::Distinct,
    ) -> Result<HashMap<String, u64>, failure::Error> {
        let key_for_distinct_lookup = &distinct.attr;
        let mut distinct_map: HashMap<String, u64> = HashMap::default();
        self.loop_over_iterator(itr, |entry| {
            // Ingore all the unstructred logs.
            if entry.structured != STRUCTURED_DATA {
                return Ok(());
            }
            // Get the value of the given json key and insert to hashmap to get
            // the distinct value.
            // TODO: avoid cloning. next should borrow value instead of Rc. But, I'm
            // keeping this way, to know more how the query layer is going to evolve.
            // Time being let's make it work. In future, if we end up in more memory
            // allocation we can optimize here. :)
            match get_value_from_json(key_for_distinct_lookup.clone(), &mut entry.line.clone()) {
                Err(e) => {
                    // Let's not return error. Just log it here.
                    warn!("unable to parse json {}", e);
                    return Ok(());
                }
                Ok(result) => {
                    let mut count_distinct = |key: String| {
                        if let Some(val) = distinct_map.get_mut(&key) {
                            *val = *val + 1;
                            return;
                        }
                        distinct_map.insert(key, 1);
                    };
                    if let Some(val) = result {
                        match val {
                            Value::String(key) => {
                                let key = key.into_owned();
                                count_distinct(key);
                            }
                            Value::Static(node) => {
                                if let Some(key) = convert_static_node_to_string(node) {
                                    count_distinct(key);
                                }
                            }
                            _ => {
                                // We don't count
                            }
                        }
                    }
                    return Ok(());
                }
            }
        })?;
        Ok(distinct_map)
    }
/// handle distinct gives the distinct count of the given log lines based on the query attr.
handle distinct gives the distinct count of the given log lines based on the query attr.
handle distinct gives the distinct count of the given log lines based on the query attr .
fn handle_distinct(
        &self,
        itr: &mut MergeIteartor<S>,
        distinct: &parser::Distinct,
    ) -> Result<HashMap<String, u64>, failure::Error> {
        let key_for_distinct_lookup = &distinct.attr;
        let mut distinct_map: HashMap<String, u64> = HashMap::default();
        self.loop_over_iterator(itr, |entry| {
            // Ingore all the unstructred logs.
            if entry.structured != STRUCTURED_DATA {
                return Ok(());
            }
            // Get the value of the given json key and insert to hashmap to get
            // the distinct value.
            // TODO: avoid cloning. next should borrow value instead of Rc. But, I'm
            // keeping this way, to know more how the query layer is going to evolve.
            // Time being let's make it work. In future, if we end up in more memory
            // allocation we can optimize here. :)
            match get_value_from_json(key_for_distinct_lookup.clone(), &mut entry.line.clone()) {
                Err(e) => {
                    // Let's not return error. Just log it here.
                    warn!("unable to parse json {}", e);
                    return Ok(());
                }
                Ok(result) => {
                    let mut count_distinct = |key: String| {
                        if let Some(val) = distinct_map.get_mut(&key) {
                            *val = *val + 1;
                            return;
                        }
                        distinct_map.insert(key, 1);
                    };
                    if let Some(val) = result {
                        match val {
                            Value::String(key) => {
                                let key = key.into_owned();
                                count_distinct(key);
                            }
                            Value::Static(node) => {
                                if let Some(key) = convert_static_node_to_string(node) {
                                    count_distinct(key);
                                }
                            }
                            _ => {
                                // We don't count
                            }
                        }
                    }
                    return Ok(());
                }
            }
        })?;
        Ok(distinct_map)
    }
fn handle_distinct ( & self , itr : & mut MergeIteartor < S > , distinct : & parser :: Distinct , ) -> Result < HashMap < String , u64 > , failure :: Error > { let key_for_distinct_lookup = & distinct . attr ; let mut distinct_map : HashMap < String , u64 > = HashMap :: default ( ) ; self . loop_over_iterator ( itr , | entry | { // Ingore all the unstructred logs. if entry . structured != STRUCTURED_DATA { return Ok ( ( ) ) ; } // Get the value of the given json key and insert to hashmap to get // the distinct value. // TODO: avoid cloning. next should borrow value instead of Rc. But, I'm // keeping this way, to know more how the query layer is going to evolve. // Time being let's make it work. In future, if we end up in more memory // allocation we can optimize here. :) match get_value_from_json ( key_for_distinct_lookup . clone ( ) , & mut entry . line . clone ( ) ) { Err ( e ) => { // Let's not return error. Just log it here. warn ! ( " " e ) ; return Ok ( ( ) ) ; } Ok ( result ) => { let mut count_distinct = | key : String | { if let Some ( val ) = distinct_map . get_mut ( & key ) { * val = * val + 1 ; return ; } distinct_map . insert ( key , 1 ) ; } ; if let Some ( val ) = result { match val { Value :: String ( key ) => { let key = key . into_owned ( ) ; count_distinct ( key ) ; } Value :: Static ( node ) => { if let Some ( key ) = convert_static_node_to_string ( node ) { count_distinct ( key ) ; } } _ => { // We don't count } } } return Ok ( ( ) ) ; } } } ) ? ; Ok ( distinct_map ) }
handle distinct gives the distinct count of the given log lines based on the query attr.
handle distinct gives the distinct count of the given log lines based on the query attr .
&self
itr
&mut MergeIteartor<S>
distinct
&parser::Distinct