code: def df_merge_select_function(
      tileable_data: TileableData, required_cols: Set[Any]
  ) -> Dict[TileableData, Set[Any]]:
      op: DataFrameMerge = tileable_data.op
      assert len(op.inputs) == 2
      assert isinstance(op.inputs[0], BaseDataFrameData)
      assert isinstance(op.inputs[1], BaseDataFrameData)
      left_data: BaseDataFrameData = op.inputs[0]
      right_data: BaseDataFrameData = op.inputs[1]
  
      ret = defaultdict(set)
      for df, suffix in zip([left_data, right_data], op.suffixes):
          for col in df.dtypes.index:
              if col in required_cols:
                  ret[df].add(col)
              else:
                  # TODO: this does not work when col is a tuple.
                  suffix_col = str(col) + suffix
                  if suffix_col in required_cols:
                      ret[df].add(col)
                      # The column in the other dataframe has to be selected as well. Otherwise, in
                      # the runtime, there will not be a column with suffix.
                      other_data = (
                          right_data if df is left_data else left_data
                      )
                      ret[other_data].add(col)
  
      if op.on is not None:
          ret[left_data].update(
              get_cols_exclude_index(left_data, op.on)
          )
          ret[right_data].update(
              get_cols_exclude_index(right_data, op.on)
          )
      if op.left_on is not None:
          ret[left_data].update(
              get_cols_exclude_index(left_data, op.left_on)
          )
      if op.right_on is not None:
          ret[right_data].update(
              get_cols_exclude_index(right_data, op.right_on)
          )
  
      return ret
  
imports: from collections import defaultdict
  from typing import Callable, Dict, Any, Set
  from .....core import TileableData
  from .....dataframe import NamedAgg
  from .....dataframe.arithmetic.core import DataFrameBinOp, DataFrameUnaryOp
  from .....dataframe.core import BaseDataFrameData, BaseSeriesData
  from .....dataframe.groupby.aggregation import DataFrameGroupByAgg
  from .....dataframe.indexing.getitem import DataFrameIndex
  from .....dataframe.indexing.setitem import DataFrameSetitem
  from .....dataframe.merge import DataFrameMerge
  from .....typing import OperandType
  from .utils import get_cols_exclude_index
label_desc: Use image node_id 2 for calling a global function with example usage: df_merge_select_function(tileable_data, required_cols) and returns: ret