code: def _get_relevant_items_by_timestamp(
      dataframe,
      col_user=DEFAULT_USER_COL,
      col_item=DEFAULT_ITEM_COL,
      col_rating=DEFAULT_RATING_COL,
      col_timestamp=DEFAULT_TIMESTAMP_COL,
      col_prediction=DEFAULT_PREDICTION_COL,
      k=DEFAULT_K,
  ):
      """Get relevant items for each customer defined by timestamp.
  
      Relevant items are defined as k items that appear mostly recently
      according to timestamps.
  
      Args:
          dataframe (pyspark.sql.DataFrame): A Spark DataFrame of customerID-itemID-rating-timeStamp
              tuples.
          col_user (str): column name for user.
          col_item (str): column name for item.
          col_rating (str): column name for rating.
          col_timestamp (str): column name for timestamp.
          col_prediction (str): column name for prediction.
          k: number of relevent items to be filtered by the function.
  
      Return:
          pyspark.sql.DataFrame: DataFrame of customerID-itemID-rating tuples with only relevant items.
      """
      window_spec = Window.partitionBy(col_user).orderBy(
          col(col_timestamp).desc()
      )
  
      items_for_user = (
          dataframe.select(
              col_user,
              col_item,
              col_rating,
              row_number().over(window_spec).alias("rank"),
          )
          .where(col("rank") <= k)
          .withColumn(
              col_prediction,
              F.collect_list(col_item).over(
                  Window.partitionBy(col_user)
              ),
          )
          .select(col_user, col_prediction)
          .dropDuplicates([col_user, col_prediction])
      )
  
      return items_for_user
  
imports: import numpy
  from recommenders.utils.constants import DEFAULT_PREDICTION_COL, DEFAULT_USER_COL, DEFAULT_ITEM_COL, DEFAULT_RATING_COL, DEFAULT_RELEVANCE_COL, DEFAULT_SIMILARITY_COL, DEFAULT_ITEM_FEATURES_COL, DEFAULT_ITEM_SIM_MEASURE, DEFAULT_TIMESTAMP_COL, DEFAULT_K, DEFAULT_THRESHOLD
label_desc: Use image node_id 3 for calling a global function with example usage: _get_relevant_items_by_timestamp(dataframe, col_user, col_item, col_rating, col_timestamp, col_prediction, k) and returns: items_for_user