2017-02-07 4 views
0

のようなSQLクエリをモデル化しようとしています。マップ内のcol2 = value2のマップからdistinct distinct(col1)を選択します。私が使用しているロジックは、各マッパーがwhere句をチェックし、一致するものが見つかった場合はwhere句の値をキーとして、col1を値として出力するというものです。デフォルトのハッシュ関数に基づいて、すべての出力はwhere節からのキー使用値と同じ減速器に送られます。減速機では、私は重複を排除して別個の値を出すことができます。これは正しいアプローチですか?マップ内のSQLモデリング

これを実装するのは正しいアプローチですか?

注:このクエリのデータは、CSVファイルにあります。

+0

[Hive](https://hive.apache.org)を試しましたか? – franklinsijo

+0

私はmap reduce frameworkを使ってそれを行う必要があります。私が使用している論理私が使用しているのは、それぞれのマッパーがwhere句をチェックし、一致するものがキーとしてwhere句を、値としてcol1を出すかどうかです。デフォルトのハッシュ関数に基づいて、すべての出力は同じ減速器に送られます。減量拠点では、重複を排除して別個の値を出すことができます。これは正しいアプローチですか? –

答えて

0
//MAPPER pseudo code 
public static class DistinctMapper extends Mapper<Object, Text, Text, NullWritable> { 
     private Text col1 = new Text(); 
     private Text col2 = new Text(); 

     public void map(Object key, Text value, Context context) throws IOException, InterruptedException { 

      // Logic to extract columns 
      String C1 = extractColumn(value); 
      String C2 = extractColumn(value); 


      if (C2 != 'WhereCluaseValue') { // filter value 
       return; 
      } 
      // Mapper output key to the distinct column value 
      col1.set(C1); 
      // Mapper value as NULL 
      context.write(col1, NullWritable.get()); 
     } 
    } 

//REDUCER pseudo code 
public static class DistinctReducer extends Reducer<Text, NullWritable, Text, NullWritable> { 
     public void reduce(Text key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException { 
      // distinct column with a null value 
      //Here we are not concerned about the list of values 
      context.write(key, NullWritable.get()); 
     } 
} 
関連する問題