<commit_before>/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2003-2007 <NAME>
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// jhyde, Mar 6, 2003
*/
package mondrian.test;

import junit.framework.Assert;
import mondrian.olap.Result;
import mondrian.olap.Member;
import mondrian.olap.Cell;
import mondrian.util.Bug;

/**
 * <code>ParentChildHierarchyTest</code> tests parent-child hierarchies.
 *
 * @author jhyde
 * @since Mar 6, 2003
 * @version $Id$
 */
public class ParentChildHierarchyTest extends FoodMartTestCase {
    public ParentChildHierarchyTest(String name) {
        super(name);
    }

    // -- Helper methods -------------------------------------------------------
    /**
     * Returns a TestContext in which the "HR" cube contains an extra dimension,
     * "EmployeesClosure", which is an explicit closure of [Employees].
     *
     * <p>[Employees] is a parent/child hierarchy (along the relationship
     * supervisor_id/employee_id). The table employee_closure expresses the
     * closure of the parent/child relation, ie it represents
     * ancestor/descendant, having a row for each ancestor/descendant pair.
     *
     * <p>The closed hierarchy has two levels: the detail level (here named
     * [Employee]) is equivalent to the base hierarchy; the [Closure] level
     * relates each descendant to all its ancestors.
     */
    private TestContext getEmpClosureTestContext() {
        return TestContext.createSubstitutingCube(
            "HR",
            "  <Dimension name=\"EmployeesClosure\" foreignKey=\"employee_id\">\n" +
                "      <Hierarchy hasAll=\"true\" allMemberName=\"All Employees\"\n" +
                "          primaryKey=\"employee_id\" primaryKeyTable=\"employee_closure\">\n" +
                "        <Join leftKey=\"supervisor_id\" rightKey=\"employee_id\">\n" +
                "          <Table name=\"employee_closure\"/>\n" +
                "          <Table name=\"employee\" alias=\"employee2\" />\n" +
                "        </Join>\n" +
                "        <Level name=\"Closure\"  type=\"Numeric\" uniqueMembers=\"false\"\n" +
                "            table=\"employee_closure\" column=\"supervisor_id\"/>\n" +
                "        <Level name=\"Employee\" type=\"Numeric\" uniqueMembers=\"true\"\n" +
                "            table=\"employee_closure\" column=\"employee_id\"/>\n" +
                "      </Hierarchy>\n" +
                "  </Dimension>");
    }

    public void testAll() {
        assertQueryReturns(
            "select {[Measures].[Org Salary], [Measures].[Count]} on columns,\n" +
                " {[Employees]} on rows\n" +
                "from [HR]",
            fold("Axis #0:\n" +
                "{}\n" +
                "Axis #1:\n" +
                "{[Measures].[Org Salary]}\n" +
                "{[Measures].[Count]}\n" +
                "Axis #2:\n" +
                "{[Employees].[All Employees]}\n" +
                "Row #0: $39,431.67\n" +
                "Row #0: 7,392\n"));
    }<commit_msg>MONDRIAN: This is a test case for bug # 1675125, the snow flake closure issue.  This bug still exists, so the test has an underscore at the beginning for now.<commit_after>/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2003-2007 <NAME>
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// jhyde, Mar 6, 2003
*/
package mondrian.test;

import junit.framework.Assert;
import mondrian.olap.Result;
import mondrian.olap.Member;
import mondrian.olap.Cell;
import mondrian.util.Bug;

/**
 * <code>ParentChildHierarchyTest</code> tests parent-child hierarchies.
 *
 * @author jhyde
 * @since Mar 6, 2003
 * @version $Id$
 */
public class ParentChildHierarchyTest extends FoodMartTestCase {
    public ParentChildHierarchyTest(String name) {
        super(name);
    }

    // -- Helper methods -------------------------------------------------------
    /**
     * Returns a TestContext in which the "HR" cube contains an extra dimension,
     * "EmployeesClosure", which is an explicit closure of [Employees].
     *
     * <p>[Employees] is a parent/child hierarchy (along the relationship
     * supervisor_id/employee_id). The table employee_closure expresses the
     * closure of the parent/child relation, ie it represents
     * ancestor/descendant, having a row for each ancestor/descendant pair.
     *
     * <p>The closed hierarchy has two levels: the detail level (here named
     * [Employee]) is equivalent to the base hierarchy; the [Closure] level
     * relates each descendant to all its ancestors.
     */
    private TestContext getEmpClosureTestContext() {
        return TestContext.createSubstitutingCube(
            "HR",
            "  <Dimension name=\"EmployeesClosure\" foreignKey=\"employee_id\">\n" +
                "      <Hierarchy hasAll=\"true\" allMemberName=\"All Employees\"\n" +
                "          primaryKey=\"employee_id\" primaryKeyTable=\"employee_closure\">\n" +
                "        <Join leftKey=\"supervisor_id\" rightKey=\"employee_id\">\n" +
                "          <Table name=\"employee_closure\"/>\n" +
                "          <Table name=\"employee\" alias=\"employee2\" />\n" +
                "        </Join>\n" +
                "        <Level name=\"Closure\"  type=\"Numeric\" uniqueMembers=\"false\"\n" +
                "            table=\"employee_closure\" column=\"supervisor_id\"/>\n" +
                "        <Level name=\"Employee\" type=\"Numeric\" uniqueMembers=\"true\"\n" +
                "            table=\"employee_closure\" column=\"employee_id\"/>\n" +
                "      </Hierarchy>\n" +
                "  </Dimension>");
    }

    /**
     * Returns a TestContext in which the "HR" cube contains an extra dimension,
     * "EmployeesSnowFlake", which is a joined hierarchy with a closure.
     * this is almost identical to employee, except we do a join with store
     * to validate joins with closures work
     */
    private TestContext getEmpSnowFlakeClosureTestContext() {
        return TestContext.createSubstitutingCube(
            "HR",
            "<Dimension name=\"EmployeeSnowFlake\" foreignKey=\"employee_id\">" +
            "<Hierarchy hasAll=\"true\" allMemberName=\"All Employees\"" +
            "    primaryKey=\"employee_id\" primaryKeyTable=\"employee\">" +
            "  <Join leftKey=\"store_id\"" +  
            "    rightAlias=\"store\" rightKey=\"store_id\">" +
            "    <Table name=\"employee\"/>" +
            "    <Table name=\"store\"/>" +
            "  </Join>" +
            "  <Level name=\"Employee Stores\" table=\"store\"" + 
            "      column=\"store_id\" uniqueMembers=\"true\"/>" +
            "  <Level name=\"Employee Id\" type=\"Numeric\" table=\"employee\" uniqueMembers=\"true\"" +
            "      column=\"employee_id\" parentColumn=\"supervisor_id\"" +
            "      nameColumn=\"full_name\" nullParentValue=\"0\">" +
            "    <Closure parentColumn=\"supervisor_id\" childColumn=\"employee_id\">" +
            "      <Table name=\"employee_closure\"/>" +
            "    </Closure>" +
            "    <Property name=\"Marital Status\" column=\"marital_status\"/>" +
            "    <Property name=\"Position Title\" column=\"position_title\"/>" +
            "    <Property name=\"Gender\" column=\"gender\"/>" +
            "    <Property name=\"Salary\" column=\"salary\"/>" +
            "    <Property name=\"Education Level\" column=\"education_level\"/>" +
            "    <Property name=\"Management Role\" column=\"management_role\"/>" +
            "  </Level>" +
            "</Hierarchy>" +
            "</Dimension>");
    }
    
    /**
     * Tests snow flake closure combination.  this is currently broken.
     * bug #1675125
     */
    public void _testSnowflakeClosure() {
        getEmpSnowFlakeClosureTestContext().assertQueryReturns(
            "select {[Measures].[Count], [Measures].[Org Salary], \n" +
                "[Measures].[Number Of Employees], [Measures].[Avg Salary]} on columns,\n" +
                "{[EmployeeSnowFlake]} on rows\n" +
                "from [HR]",
            fold("Axis #0:\n" +
                "{}\n" +
                "Axis #1:\n" +
                "{[Measures].[Count]}\n" +
                "{[Measures].[Org Salary]}\n" +
                "{[Measures].[Number of Employees]}\n" +
                "{[Measures].[Avg Salary]}\n" +
                "Axis #2:\n" +
                "{[EmployeeSnowFlake].[All Employees]}\n" +
                "Row #0: 7,392\n" +
                "Row #0: $39,431.67\n" +
                "Row #0: 616\n" +
                "Row #0: $64.01\n"));
    }
    
    public void testAll() {
        assertQueryReturns(
            "select {[Measures].[Org Salary], [Measures].[Count]} on columns,\n" +
                " {[Employees]} on rows\n" +
                "from [HR]",
            fold("Axis #0:\n" +
                "{}\n" +
                "Axis #1:\n" +
                "{[Measures].[Org Salary]}\n" +
                "{[Measures].[Count]}\n" +
                "Axis #2:\n" +
                "{[Employees].[All Employees]}\n" +
                "Row #0: $39,431.67\n" +
                "Row #0: 7,392\n"));
    }
{'fraction_non_alphanumeric': 0.16120644825793032, 'fraction_numerical': 0.011440457618304731, 'mean_word_length': 1.8542594241614723, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6436835', 'n_tokens_mistral': 2924, 'n_tokens_neox': 2653, 'n_words': 658}