//Desciption: Joins the instance of R1 and the instance of R2
        //Precondition: Files must exist and be in the appropriate folders. Attributes must be valid.
        public string Join(string R1FileName, string R2FileName, string R1Attr, string R2Attr)
        {
            //local vars
            OuterTable outerTableForJoin = null;
            InnerTable innerTableForJoin = null;
            string     joinResult;

            //iterate through R1 instances
            foreach (OuterTable outerTable in outerTables)
            {
                if (outerTable.relationName == R1FileName)
                {
                    outerTableForJoin = outerTable;
                    break;
                }
            }

            //iterate through R2 instances
            foreach (InnerTable innerTable in innerTables)
            {
                if (innerTable.relationName == R2FileName)
                {
                    innerTableForJoin = innerTable;
                    break;
                }
            }

            //do join
            joinResult = outerTableForJoin.HashJoin(innerTableForJoin, R1Attr, R2Attr);

            //return result
            return(joinResult);
        }
        //Description: Gets selectivity of a join
        public double SelectivityOfJoin(string R1FileName, string R2FileName, string R1Attr, string R2Attr)
        {
            //local vars
            string joinResult;

            String[]   linesOfJoinResult;
            double     selectivityOfJoin;
            OuterTable outerTableOfJoin = null;
            InnerTable innerTableOfJoin = null;

            //find OuterTable object for R1FileName
            foreach (OuterTable outerTable in outerTables)
            {
                if (outerTable.relationName == R1FileName)
                {
                    outerTableOfJoin = outerTable;
                    break;
                }
            }

            //find InnerTable object for R2FileName
            foreach (InnerTable innerTable in innerTables)
            {
                if (innerTable.relationName == R2FileName)
                {
                    innerTableOfJoin = innerTable;
                    break;
                }
            }

            //do join
            joinResult = Join(R1FileName, R2FileName, R1Attr, R2Attr);

            //split joinResult into its separate lines
            linesOfJoinResult = joinResult.Split('\n');

            //calcualte selectivity of join
            selectivityOfJoin = ((double)(linesOfJoinResult.Length - 1)) / (outerTableOfJoin.numRows * innerTableOfJoin.numRows);

            return(selectivityOfJoin);
        }
Пример #3
0
        private void ClickEvent(object sender, RoutedEventArgs e)
        {
            //local vars
            string joinResult;

            String[] linesOfJoinResult;
            double   selectivityOfJoin;

            //if one of the combo boxes has nothing selected
            if ((R1AttributeComboBox.SelectedIndex == -1) || (R2AttributeComboBox.SelectedIndex == -1) ||
                (R1InstanceComboBox.SelectedIndex == -1) || (R2InstanceComboBox.SelectedIndex == -1))
            {
                MessageBox.Show("You must make a selection for each Drop Down Box. Try again.");
                return;
            }

            //Remove all items from R1ListBox
            while (R1ListBox.Items.Count != 0)
            {
                R1ListBox.Items.RemoveAt(0);
            }

            //remove all items from R2ListBox
            while (R2ListBox.Items.Count != 0)
            {
                R2ListBox.Items.RemoveAt(0);
            }

            //remove all items from JoinResultListBox
            while (JoinResultListBox.Items.Count != 0)
            {
                JoinResultListBox.Items.RemoveAt(0);
            }

            //find selected R1 instance
            foreach (OuterTable outerTable in tableManager.outerTables)
            {
                if (outerTable.relationName == (string)R1InstanceComboBox.Items.GetItemAt(R1InstanceComboBox.SelectedIndex))
                {
                    selectedOuterTable = outerTable;
                }
            }

            //find selected R2 instance
            foreach (InnerTable innerTable in tableManager.innerTables)
            {
                if (innerTable.relationName == (string)R2InstanceComboBox.Items.GetItemAt(R2InstanceComboBox.SelectedIndex))
                {
                    selectedInnerTable = innerTable;
                }
            }

            //get selected R1 attribute
            selectedR1Attribute = (string)((ComboBoxItem)R1AttributeComboBox.Items.GetItemAt(R1AttributeComboBox.SelectedIndex)).Content;

            //get selected R2 attribute
            selectedR2Attribute = (string)((ComboBoxItem)R2AttributeComboBox.Items.GetItemAt(R2AttributeComboBox.SelectedIndex)).Content;

            //fill list box for R1
            foreach (String line in selectedOuterTable.outerTableFile)
            {
                R1ListBox.Items.Add(line);
            }

            //fill list box for R2
            foreach (String line in selectedInnerTable.innerTableFile)
            {
                R2ListBox.Items.Add(line);
            }

            //do join
            joinResult = tableManager.Join(selectedOuterTable.relationName, selectedInnerTable.relationName, selectedR1Attribute, selectedR2Attribute);

            //split join result into the separate lines
            linesOfJoinResult = joinResult.Split('\n');

            //remove '\r' from the end of each string
            for (int i = 0; i < linesOfJoinResult.Length - 1; ++i)
            {
                linesOfJoinResult[i] = linesOfJoinResult[i].Substring(0, linesOfJoinResult[i].Length - 1);
            }

            //put join result in list box
            foreach (string line in linesOfJoinResult)
            {
                JoinResultListBox.Items.Add(line);
            }

            //calculate selectivity
            selectivityOfJoin = tableManager.SelectivityOfJoin(selectedOuterTable.relationName, selectedInnerTable.relationName, selectedR1Attribute, selectedR2Attribute);

            //set selectivity label
            SelectivityOfJoinLabel.Text = "Selectivity of Join: " + Convert.ToString(selectivityOfJoin);
        }