猪交叉加入并更换

时间:2016-03-15 21:39:27

标签: hadoop mapreduce apache-pig

我有两个文件。一个文件的数据如下

Ram,C,Bnglr
Shyam,A,Kolkata

另一个文件有一个参考

C,Calicut
A,Ahmedabad

现在使用pig,我想搜索并替换原始文件中的数据以创建新文件,以便我可以使用这两个文件创建一个新文件。

Ram,Class,Bnglr
Shyam,Ahmedabad,Kolkata

猪可能吗?我知道如何在MR中做到这一点,但想在猪身上试一试。

2 个答案:

答案 0 :(得分:1)

是。加入文件并选择所需的列并写入新文件

private void setUpSingleSearch(final Menu menu, final MenuItem singleSearchItem) {
    searchView = (SearchView) MenuItemCompat.getActionView(singleSearchItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            displaySuggestions(newText);
            return false;
        }
    });
}

private void displaySuggestions(String query) {
    MatrixCursor matrixCursor = new MatrixCursor(new String[]{BaseColumns._ID,
            RestaurantTable.Cols.NAME, RestaurantTable.Cols.ID});
    RestaurantListing restaurantListing = new RestaurantListing(getContext());
    restaurantListing.getRestaurantSuggestions(currListName, "Name", matrixCursor, query);

    setUpSearchViewSuggestions(matrixCursor);
}

private void setUpSearchViewSuggestions(MatrixCursor cursor) {
    String[] from = new String[]{RestaurantTable.Cols.NAME};
    int[] to = new int[]{android.R.id.text1};
    android.support.v4.widget.SimpleCursorAdapter adapter = new android.support.v4.widget.SimpleCursorAdapter(
            getActivity().getBaseContext(),
            R.layout.search_view_suggestions_list_item,
            cursor,
            from,
            to,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    searchView.setSuggestionsAdapter(adapter);
}

答案 1 :(得分:0)

以上逻辑可行,但如果您在第二个文件中没有匹配的记录,那么您将错过来自file1的记录