<commit_before>require "spec_helper"

describe "Cube" do
  before(:all) do
    @schema = Mondrian::OLAP::Schema.define do
      measures_caption 'Measures caption'

      cube 'Sales' do
        description 'Sales description'
        caption 'Sales caption'
        annotations :foo => 'bar'
        table 'sales'
        visible true
        dimension 'Gender', :foreign_key => 'customer_id' do
          description 'Gender description'
          caption 'Gender caption'
          visible true
          hierarchy :has_all => true, :primary_key => 'id' do
            description 'Gender hierarchy description'
            caption 'Gender hierarchy caption'
            all_member_name 'All Genders'
            all_member_caption 'All Genders caption'
            table 'customers'
            visible true
            level 'Gender', :column => 'gender', :unique_members => true,
                            :description => 'Gender level description', :caption => 'Gender level caption' do
              visible true
              # Dimension values SQL generated by caption_expression fails on PostgreSQL and MS SQL
              if %w(mysql oracle).include?(MONDRIAN_DRIVER)
                caption_expression do
                  sql "'dummy'"
                end
              end
            end
          end
        end
        dimension 'Customers', :foreign_key => 'customer_id', :annotations => {:foo => 'bar'} do
          hierarchy :has_all => true, :all_member_name => 'All Customers', :primary_key => 'id', :annotations => {:foo => 'bar'} do
            table 'customers'
            level 'Country', :column => 'country', :unique_members => true, :annotations => {:foo => 'bar'}
            level 'State Province', :column => 'state_province', :unique_members => true
            level 'City', :column => 'city', :unique_members => false
            level 'Name', :column => 'fullname', :unique_members => true
          end
        end
        calculated_member 'Non-USA', :annotations => {:foo => 'bar'} do
          dimension 'Customers'
          formula '[Customers].[All Customers] - [Customers].[USA]'
        end
        dimension 'Time', :foreign_key => 'time_id', :type => 'TimeDimension' do
          hierarchy :has_all => false, :primary_key => 'id' do
            table 'time'
            level 'Year', :column => 'the_year', :type => 'Numeric', :unique_members => true, :level_type => 'TimeYears'
            level 'Quarter', :column => 'quarter', :unique_members => false, :level_type => 'TimeQuarters'
            level 'Month', :column => 'month_of_year', :type => 'Numeric', :unique_members => false, :level_type => 'TimeMonths'
          end
          hierarchy 'Weekly', :has_all => false, :primary_key => 'id' do
            table 'time'
            level 'Year', :column => 'the_year', :type => 'Numeric', :unique_members => true, :level_type => 'TimeYears'
            level 'Week', :column => 'weak_of_year', :type => 'Numeric', :unique_members => false, :level_type => 'TimeWeeks'
          end
        end
        calculated_member 'Last week' do
          hierarchy '[Time.Weekly]'
          formula 'Tail([Time.Weekly].[Week].Members).Item(0)'
        end
        measure 'Unit Sales', :column => 'unit_sales', :aggregator => 'sum', :annotations => {:foo => 'bar'}
        measure 'Store Sales', :column => 'store_sales', :aggregator => 'sum'
        measure 'Store Cost', :column => 'store_cost', :aggregator => 'sum', :visible => false
      end
    end
    @olap = Mondrian::OLAP::Connection.create(CONNECTION_PARAMS.merge :schema => @schema)
  end

  # Do not execute tests on analytical databases with slow individual inserts
  describe 'cache', unless: %w(vertica snowflake).include?(MONDRIAN_DRIVER) do
    def qt(name)
      @connection.quote_table_name(name.to_s)
    end

    before(:all) do
      @connection = ActiveRecord::Base.connection
      @cube = @olap.cube('Sales')
      @query = <<-SQL
        SELECT {[Measures].[Store Cost], [Measures].[Store Sales]} ON COLUMNS
        FROM  [Sales]
        WHERE ([Time].[2010].[Q1], [Customers].[USA].[CA])
      SQL

      case MONDRIAN_DRIVER
      when 'mysql', 'jdbc_mysql', 'postgresql', 'oracle'
        @connection.execute 'CREATE TABLE sales_copy AS SELECT * FROM sales'
      when 'mssql', 'sqlserver'
        # Use raw_connection.execute to avoid detecting this query as a SELECT query
        # for which executeQuery JDBC method will fail
        @connection.raw_connection.execute_update 'SELECT * INTO sales_copy FROM sales'
      end
    end

    after(:each) do
      @connection.execute 'TRUNCATE TABLE sales'
      @connection.execute 'INSERT INTO sales SELECT * FROM sales_copy'
<commit_msg>Do not run cache control tests on ClickHouse<commit_after>require "spec_helper"

describe "Cube" do
  before(:all) do
    @schema = Mondrian::OLAP::Schema.define do
      measures_caption 'Measures caption'

      cube 'Sales' do
        description 'Sales description'
        caption 'Sales caption'
        annotations :foo => 'bar'
        table 'sales'
        visible true
        dimension 'Gender', :foreign_key => 'customer_id' do
          description 'Gender description'
          caption 'Gender caption'
          visible true
          hierarchy :has_all => true, :primary_key => 'id' do
            description 'Gender hierarchy description'
            caption 'Gender hierarchy caption'
            all_member_name 'All Genders'
            all_member_caption 'All Genders caption'
            table 'customers'
            visible true
            level 'Gender', :column => 'gender', :unique_members => true,
                            :description => 'Gender level description', :caption => 'Gender level caption' do
              visible true
              # Dimension values SQL generated by caption_expression fails on PostgreSQL and MS SQL
              if %w(mysql oracle).include?(MONDRIAN_DRIVER)
                caption_expression do
                  sql "'dummy'"
                end
              end
            end
          end
        end
        dimension 'Customers', :foreign_key => 'customer_id', :annotations => {:foo => 'bar'} do
          hierarchy :has_all => true, :all_member_name => 'All Customers', :primary_key => 'id', :annotations => {:foo => 'bar'} do
            table 'customers'
            level 'Country', :column => 'country', :unique_members => true, :annotations => {:foo => 'bar'}
            level 'State Province', :column => 'state_province', :unique_members => true
            level 'City', :column => 'city', :unique_members => false
            level 'Name', :column => 'fullname', :unique_members => true
          end
        end
        calculated_member 'Non-USA', :annotations => {:foo => 'bar'} do
          dimension 'Customers'
          formula '[Customers].[All Customers] - [Customers].[USA]'
        end
        dimension 'Time', :foreign_key => 'time_id', :type => 'TimeDimension' do
          hierarchy :has_all => false, :primary_key => 'id' do
            table 'time'
            level 'Year', :column => 'the_year', :type => 'Numeric', :unique_members => true, :level_type => 'TimeYears'
            level 'Quarter', :column => 'quarter', :unique_members => false, :level_type => 'TimeQuarters'
            level 'Month', :column => 'month_of_year', :type => 'Numeric', :unique_members => false, :level_type => 'TimeMonths'
          end
          hierarchy 'Weekly', :has_all => false, :primary_key => 'id' do
            table 'time'
            level 'Year', :column => 'the_year', :type => 'Numeric', :unique_members => true, :level_type => 'TimeYears'
            level 'Week', :column => 'weak_of_year', :type => 'Numeric', :unique_members => false, :level_type => 'TimeWeeks'
          end
        end
        calculated_member 'Last week' do
          hierarchy '[Time.Weekly]'
          formula 'Tail([Time.Weekly].[Week].Members).Item(0)'
        end
        measure 'Unit Sales', :column => 'unit_sales', :aggregator => 'sum', :annotations => {:foo => 'bar'}
        measure 'Store Sales', :column => 'store_sales', :aggregator => 'sum'
        measure 'Store Cost', :column => 'store_cost', :aggregator => 'sum', :visible => false
      end
    end
    @olap = Mondrian::OLAP::Connection.create(CONNECTION_PARAMS.merge :schema => @schema)
  end

  # Do not execute tests on analytical databases with slow individual inserts
  describe 'cache', unless: %w(vertica snowflake clickhouse).include?(MONDRIAN_DRIVER) do
    def qt(name)
      @connection.quote_table_name(name.to_s)
    end

    before(:all) do
      @connection = ActiveRecord::Base.connection
      @cube = @olap.cube('Sales')
      @query = <<-SQL
        SELECT {[Measures].[Store Cost], [Measures].[Store Sales]} ON COLUMNS
        FROM  [Sales]
        WHERE ([Time].[2010].[Q1], [Customers].[USA].[CA])
      SQL

      case MONDRIAN_DRIVER
      when 'mysql', 'jdbc_mysql', 'postgresql', 'oracle'
        @connection.execute 'CREATE TABLE sales_copy AS SELECT * FROM sales'
      when 'mssql', 'sqlserver'
        # Use raw_connection.execute to avoid detecting this query as a SELECT query
        # for which executeQuery JDBC method will fail
        @connection.raw_connection.execute_update 'SELECT * INTO sales_copy FROM sales'
      end
    end

    after(:each) do
      @connection.execute 'TRUNCATE TABLE sales'
      @connection.execute 'INSERT INTO sales SELECT * FROM sales_copy'

{'fraction_non_alphanumeric': 0.12552742616033755, 'fraction_numerical': 0.0012658227848101266, 'mean_word_length': 2.49723349317595, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 129, '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': '5914501', 'n_tokens_mistral': 2718, 'n_tokens_neox': 2584, 'n_words': 786}