public TableData join (String outputName,TableData leftTable, TableData rightTable, 
			ArrayList <String> leftHash, ArrayList <String> rightHash,
			OutputStructure outputStructure, String selectionStatement) 
	{
		System.out.println ("Start running a join on "+outputName);

		ArrayList <Attribute> inAttsLeft = getAttrFromTable(leftTable);
		ArrayList <Attribute> inAttsRight = getAttrFromTable(rightTable);
		ArrayList <Attribute> outAtts = outputStructure.getOutAtts();

		String selection = selectionStatement;
		HashMap <String, String> exprs = outputStructure.getExprs(); 

		//save the information for the output table
		int outIndex=0;
		Map <String, AttInfo> outputAttrs=new HashMap<String, AttInfo>();
		Iterator<Attribute> outAttsIter=outAtts.iterator();
		while(outAttsIter.hasNext())
		{
			Attribute a=outAttsIter.next();
			String name=a.getName();
			if(name.substring(name.length()-3, name.length()).equals("out"))
			{
				name=name.substring(0,name.length()-3);
			}
			else if(name.length()>=8)
			{
				if(name.substring(name.length()-7, name.length()).equals("outLeft"))
				{
					name=name.substring(0,name.length()-7);
				}
				else if(name.substring(name.length()-8, name.length()).equals("outRight"))
				{
					name=name.substring(0,name.length()-8);
				}
			}
			AttInfo ai=new AttInfo(name,a.getType(),outIndex++);
			outputAttrs.put(name, ai);
		}

		TableData output=new TableData(outputName, outputAttrs);

		// run the join
		try {
			
			System.out.println("inAttsLeft:\n");
			print(inAttsLeft);
			System.out.println("inAttsRight:\n");
			print(inAttsRight);
			Iterator<String> iterl=leftHash.iterator();
			while(iterl.hasNext())
			{
				System.out.println("leftHash: "+iterl.next());
			}

			Iterator<String> iterr=rightHash.iterator();
			while(iterr.hasNext())
			{
				System.out.println("rightHash: "+iterr.next());
			}
			System.out.println("outAtts:\n");
			print(outAtts);
			System.out.println("selection:\n");
			System.out.println(selection+"\n");
			System.out.println("exprs:\n");
			Set<String> exp=exprs.keySet();
			Iterator<String> itera=exp.iterator();
			while(itera.hasNext())
			{
				String ss=itera.next();
				System.out.println(ss+" "+exprs.get(ss)+"\n");
			}
			System.out.println("Files: lef="+leftTable.getName()+".tbl right="+rightTable.getName()+".tbl");
			

			Join foo = new Join (inAttsLeft, inAttsRight, outAtts, leftHash, rightHash, selection, 
					exprs, leftTable.getName()+".tbl", rightTable.getName()+".tbl", outputName+".tbl",
					"g++", "cppDir/"); 

			System.out.println(output.print());
			return output;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException (e);
		}

	}