 }
 
 public extension Query where DS : JoinProtocol, DS.Left : Table {
-    public func map(_ f: (DS.Left, DS.Right)->[String]) -> QueryImpl<Join<DS.Left, DS.Right>> {
-        fatalError()
+    public func map(_ f: (DS.Left, DS.Right)->[Column]) -> QueryImpl<Join<DS.Left, DS.Right>> {
+        var colmap = [String: [String]]()
+        
+        let datasets = dataset.datasets
+        let (left, right) = datasets
+        
+        let cols = datasets |> f
+        for col in cols {
+            let name = col.table.name
+            if colmap[name] == nil {
+                colmap[name] = [String]()
+            }
+            colmap[name]!.append(col.name)
+        }
+        
+        let newleft = DS.Left(name: left.name, columns: .list(colmap[left.name] ?? []))
+        let newright = DS.Right(name: right.name, columns: .list(colmap[right.name] ?? []))
+        
+        let join = dataset.replace(left: newleft, right: newright)
+        
+        return QueryImpl(connection: connection,
+                         dataset: join,
+                         predicate: predicate,
+                         order: order)
     }
 }
 

    public init(name:String, columns:Columns = .all) {
        self.name = name
        self.columns = columns
    }
}



let pool = rdbc.pool(url: "sqlite:///tmp/crlrsdc.sqlite")

let t1 = pool.select(from: "test1").map{ $0["firstname"] }
let t2 = pool.select(from: "test2").map("lastname")

t1.join(t2).map { t1, t2 in
    [t1["a"], t2["b"]]
}

//t1.join(t2) { t1, t2 in t1["id"] == t2["id"] }.filter { t1, _ in t1["firstname"] == "Daniel" || t2["lastname"] == "Lennon" }
