<commit_before>module ThinkingSphinx
  class OracleAdapter < AbstractAdapter
    def setup
      create_group_concat_function
      create_crc32_function
    end
    
    def sphinx_identifier
      "odbc"
    end
    
    def concatenate(clause, separator = ' ')
      clause.split(', ').collect { |field| field }.join(" || '#{separator}' || ")
    end
    
    def group_concatenate(clause, separator = ' ')
      "TO_STRING(CAST(COLLECT(TO_CHAR(#{clause})) AS SYS.ODCIVARCHAR2LIST), '#{separator}')"
    end
    
    def cast_to_string(clause)
      "TO_CHAR(#{clause})"
    end
    
    def cast_to_datetime(clause)
      "(TO_DATE(TO_CHAR(#{clause}, 'YYYY-MON-DD HH24.MI.SS'), 'YYYY-MON-DD HH24.MI.SS') - TO_DATE('01-JAN-1970','DD-MON-YYYY')) * (86400)"
    end
    
    def cast_to_unsigned(clause)
      "CAST(#{clause} AS NUMBER(10,0))"
    end
    
    def convert_nulls(clause, default = '')
      return clause if default == ''
      default = "'#{default}'" if default.is_a?(String)
      "NVL(#{clause},#{default})"
    end
    
    def boolean(value)
      value ? '1' : '0'
    end
    
    # TODO
    def crc(clause, blank_to_null = false)
      "CRC32(#{clause})"
    end
    
    def utf8_query_pre
      nil
    end
    
    def time_difference(diff)
      "SYSDATE - #{diff}/(86400)"
    end
    
    def select_each(query)
      cursor = connection.raw_connection.exec(query)
      col_names = cursor.get_col_names.collect(&:downcase)<commit_msg>make cast_to_datetime work with timezones<commit_after>module ThinkingSphinx
  class OracleAdapter < AbstractAdapter
    def setup
      create_group_concat_function
      create_crc32_function
    end
    
    def sphinx_identifier
      "odbc"
    end
    
    def concatenate(clause, separator = ' ')
      clause.split(', ').collect { |field| field }.join(" || '#{separator}' || ")
    end
    
    def group_concatenate(clause, separator = ' ')
      "TO_STRING(CAST(COLLECT(TO_CHAR(#{clause})) AS SYS.ODCIVARCHAR2LIST), '#{separator}')"
    end
    
    def cast_to_string(clause)
      "TO_CHAR(#{clause})"
    end
    
    # Works the same way as described here:
    # http://github.com/freelancing-god/thinking-sphinx/issues#issue/13
    #
    # With oracle_enhanced you can specify "time_zone" in database.yml
    def cast_to_datetime(clause)
      "((SYSDATE + (#{clause} - timestamp '1970-01-01 00:00:00 +00:00') - SYSDATE) * 86400)"
    end
    
    def cast_to_unsigned(clause)
      "CAST(#{clause} AS NUMBER(10,0))"
    end
    
    def convert_nulls(clause, default = '')
      return clause if default == ''
      default = "'#{default}'" if default.is_a?(String)
      "NVL(#{clause},#{default})"
    end
    
    def boolean(value)
      value ? '1' : '0'
    end
    
    def crc(clause, blank_to_null = false)
      "CRC32(#{clause})"
    end
    
    def utf8_query_pre
      nil
    end
    
    def time_difference(diff)
      "SYSDATE - #{diff}/(86400)"
    end
    
    def select_each(query)
      cursor = connection.raw_connection.exec(query)
      col_names = cursor.get_col_names.collect(&:downcase)
{'fraction_non_alphanumeric': 0.13202065848934796, 'fraction_numerical': 0.023240800516462233, 'mean_word_length': 2.61610268378063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6640851', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1094, 'n_words': 205}