// Path: reference/src/main/java/me/doubledutch/stroom/client/StreamConnection.java
// public interface StreamConnection{
// 	public final static int LINEAR=0;
// 	public final static int SYNC=1;
// 	public final static int FLUSH=2;
// 	public final static int NONE=3;
// 
// 	public List<String> get(long index,long endIndex) throws IOException;
// 	public String get(long index) throws IOException;
// 	public String getLast() throws IOException;
// 	public long getCount() throws IOException;
// 	
// 	public long append(JSONObject data) throws IOException,JSONException;
// 	public long append(String data) throws IOException,JSONException;
// 	public List<Long> append(List<String> data) throws IOException,JSONException;
// 	
// 	public long append(JSONObject data,int hint) throws IOException,JSONException;
// 	public long append(String data,int hint) throws IOException,JSONException;
// 	public List<Long> append(List<String> data,int hint) throws IOException,JSONException;
// 
// 	public void truncate(long index) throws IOException;
// }


import me.doubledutch.stroom.client.*;
import me.doubledutch.stroom.streams.*;
import me.doubledutch.stroom.query.sql.*;
import me.doubledutch.stroom.*;
import me.doubledutch.stroom.client.StreamConnection;
import me.doubledutch.lazyjson.*;
import org.json.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;
		while(table.hasNext()){
			LazyObject obj=table.next();
			JSONObject out=new JSONObject();
			for(DerivedColumn col:columns){
				col.pickAndPlace(obj,out);
			}
			LazyObject outObj=new LazyObject(out.toString());
			String key=query.getPartitionKey(obj);
			// TODO: this is such a hack - make smarter
			if(key==null)key=query.getPartitionKey(outObj);
			TempTable partition=getPartition(key);
			partition.append(outObj);
			// picked.append(new LazyObject(out.toString()));
		}
		// return picked;
	}

	public TempTable scan(TableReference table) throws Exception{
		if(table.query!=null){
			QueryRunner sub=new QueryRunner(table.query);
			sub.run();
			if(table.condition!=null){
				// Run through it
			}else{
				return sub.getResult();
			}
		}else if(table.url!=null){
			// System.out.println("scanning url");
			TempTable temp=createTempTable();
			Stroom s=new Stroom();
// Path: reference/src/main/java/me/doubledutch/stroom/client/StreamConnection.java
// public interface StreamConnection{
// 	public final static int LINEAR=0;
// 	public final static int SYNC=1;
// 	public final static int FLUSH=2;
// 	public final static int NONE=3;
// 
// 	public List<String> get(long index,long endIndex) throws IOException;
// 	public String get(long index) throws IOException;
// 	public String getLast() throws IOException;
// 	public long getCount() throws IOException;
// 	
// 	public long append(JSONObject data) throws IOException,JSONException;
// 	public long append(String data) throws IOException,JSONException;
// 	public List<Long> append(List<String> data) throws IOException,JSONException;
// 	
// 	public long append(JSONObject data,int hint) throws IOException,JSONException;
// 	public long append(String data,int hint) throws IOException,JSONException;
// 	public List<Long> append(List<String> data,int hint) throws IOException,JSONException;
// 
// 	public void truncate(long index) throws IOException;
// }


// Path: reference/src/main/java/me/doubledutch/stroom/query/QueryRunner.java
import me.doubledutch.stroom.client.*;
import me.doubledutch.stroom.streams.*;
import me.doubledutch.stroom.query.sql.*;
import me.doubledutch.stroom.*;
import me.doubledutch.stroom.client.StreamConnection;
import me.doubledutch.lazyjson.*;
import org.json.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;

		while(table.hasNext()){
			LazyObject obj=table.next();
			JSONObject out=new JSONObject();
			for(DerivedColumn col:columns){
				col.pickAndPlace(obj,out);
			}
			LazyObject outObj=new LazyObject(out.toString());
			String key=query.getPartitionKey(obj);
			// TODO: this is such a hack - make smarter
			if(key==null)key=query.getPartitionKey(outObj);
			TempTable partition=getPartition(key);
			partition.append(outObj);
			// picked.append(new LazyObject(out.toString()));
		}
		// return picked;
	}

	public TempTable scan(TableReference table) throws Exception{
		if(table.query!=null){
			QueryRunner sub=new QueryRunner(table.query);
			sub.run();
			if(table.condition!=null){
				// Run through it
			}else{
				return sub.getResult();
			}
		}else if(table.url!=null){
			// System.out.println("scanning url");
			TempTable temp=createTempTable();
			Stroom s=new Stroom();
			StreamConnection stream=s.openStream(table.url);