class_docstr: Confluence Pages Table implementation
class_docstr_tok: ["Confluence","Pages","Table","implementation"]
docstr: Pulls data from the Confluence "get_all_pages_from_space" API endpoint
  Parameters
  ----------
  query : ast.Select
     Given SQL SELECT query
  Returns
  -------
  pd.DataFrame
      confluence "get_all_pages_from_space" matching the query
  Raises
  ------
  ValueError
      If the query contains an unsupported condition
docstr_tok: ["Pulls","data","from","the","Confluence","``","get_all_pages_from_space","''","API","endpoint","Parameters","--","--","--","--","--","query",":","ast.Select","Given","SQL","SELECT","query","Returns","--","--","--","-","pd.DataFrame","confluence","``","get_all_pages_from_space","''","matching","the","query","Raises","--","--","--","ValueError","If","the","query","contains","an","unsupported","condition"]
code: def select(self, query: ast.Select) -> pd.DataFrame:
      """Pulls data from the Confluence "get_all_pages_from_space" API endpoint
      Parameters
      ----------
      query : ast.Select
         Given SQL SELECT query
      Returns
      -------
      pd.DataFrame
          confluence "get_all_pages_from_space" matching the query
      Raises
      ------
      ValueError
          If the query contains an unsupported condition
      """
      conditions = extract_comparison_conditions(query.where)
  
      if query.limit:
          total_results = query.limit.value
      else:
          total_results = 50
  
      pages_kwargs = {}
      order_by_conditions = {}
  
      if query.order_by and len(query.order_by) > 0:
          order_by_conditions["columns"] = []
          order_by_conditions["ascending"] = []
  
          for an_order in query.order_by:
              if an_order.field.parts[0] != "":
                  next
              if an_order.field.parts[1] in self.get_columns():
                  order_by_conditions["columns"].append(
                      an_order.field.parts[1]
                  )
  
                  if an_order.direction == "ASC":
                      order_by_conditions["ascending"].append(True)
                  else:
                      order_by_conditions["ascending"].append(False)
              else:
                  raise ValueError(
                      f"Order by unknown column {an_order.field.parts[1]}"
                  )
  
      for a_where in conditions:
          if a_where[1] == "space":
              space_name = a_where[2]
              if a_where[0] != "=":
                  raise ValueError(
                      "Unsupported where operation for space"
                  )
              pages_kwargs["space"] = space_name
          elif a_where[1] not in ["id", "space"]:
              raise ValueError(
                  f"Unsupported where argument {a_where[1]}"
              )
  
      confluence_pages_records = (
          self.handler.connect().get_all_pages_from_space(
              space_name,
              start=0,
              limit=total_results,
              expand="body.storage",
          )
      )
      confluence_pages_df = pd.json_normalize(confluence_pages_records)
  
      for a_where in conditions:
          if a_where[1] == "id":
              id = a_where[2]
              if a_where[0] != "=":
                  raise ValueError("Unsupported where operation for id")
              confluence_pages_df = confluence_pages_df[
                  confluence_pages_df.id == id
              ]
  
      def extract_space(input_string):
          parts = input_string.split("/")
          return parts[-1]
  
      confluence_pages_df["space"] = confluence_pages_df[
          "_expandable.space"
      ].apply(extract_space)
  
      confluence_pages_df.columns = (
          confluence_pages_df.columns.str.replace(
              "body.storage.value", "body"
          )
      )
  
      confluence_pages_df = confluence_pages_df[self.get_columns()]
  
      if "space" in pages_kwargs:
          confluence_pages_df = confluence_pages_df[
              confluence_pages_df.space == pages_kwargs["space"]
          ]
  
      selected_columns = []
      for target in query.targets:
          if isinstance(target, ast.Star):
              selected_columns = self.get_columns()
              break
          elif isinstance(target, ast.Identifier):
              selected_columns.append(target.parts[-1])
          else:
              raise ValueError(f"Unknown query target {type(target)}")
  
      if len(confluence_pages_df) == 0:
          confluence_pages_df = pd.DataFrame(
              [], columns=selected_columns
          )
      else:
          confluence_pages_df.columns = self.get_columns()
          for col in set(confluence_pages_df.columns).difference(
              set(selected_columns)
          ):
              confluence_pages_df = confluence_pages_df.drop(
                  col, axis=1
              )
  
          if len(order_by_conditions.get("columns", [])) > 0:
              confluence_pages_df = confluence_pages_df.sort_values(
                  by=order_by_conditions["columns"],
                  ascending=order_by_conditions["ascending"],
              )
  
      return confluence_pages_df
  
file_path: mindsdb/mindsdb/integrations/handlers/confluence_handler/confluence_table.py
imports: from typing import List
  import pandas
  from mindsdb_sql.parser import ast
  from mindsdb.integrations.libs.api_handler import APITable
  from mindsdb.integrations.utilities.sql_utils import extract_comparison_conditions
  from mindsdb.utilities import log
  from mindsdb_sql.parser import ast
label_desc: Use image node_id 1 for calling the ConfluencePagesTable obj's underlying member method code with example usage: obj.select(query) and returns: confluence_pages_df, parts