<commit_before>package ch.wsl.box.model

import io.circe._
import ch.wsl.box.rest.utils.JSONSupport._
import geotrellis.vector.io.json.Implicits._
import Light._
import slick.dbio.DBIO
import ch.wsl.box.jdbc.PostgresProfile.api._
import ch.wsl.box.model.boxentities.BoxSchema
import ch.wsl.box.model.shared.{Filter, JSONQuery, JSONQueryFilter, JSONSort}
import ch.wsl.box.rest.runtime.Registry
import ch.wsl.box.shared.utils.DateTimeFormatters
import org.locationtech.jts.geom.{Geometry, GeometryFactory}
import slick.jdbc.{PositionedParameters, SQLActionBuilder, SetParameter}

import java.util.{Base64, UUID}
import scala.concurrent.ExecutionContext
import scala.util.Try

trait UpdateTable[T] { t:Table[T] =>
  protected def doUpdateReturning(fields:Map[String,Json],where:SQLActionBuilder):DBIO[T]
  protected def doSelectLight(where:SQLActionBuilder):DBIO[Seq[T]]

  private def orderBlock(order:JSONSort):SQLActionBuilder = sql" #${order.column} #${order.order} "

  protected def whereBuilder(query: JSONQuery): SQLActionBuilder = {
    val kv = jsonQueryComposer(this)
    val where = if(query.filter.nonEmpty) {
      val filters = query.filter.flatMap(kv)
      filters.tail.foldLeft(concat(sql" where ", filters.head)) { case (builder, pair) => concat(builder, concat(sql" and ", pair)) }
    } else sql""

    val order = if(query.sort.nonEmpty)
      query.sort.tail.foldLeft(concat(sql" order by ", orderBlock(query.sort.head))) { case (builder, pair) => concat(builder, concat(sql" , ", orderBlock(pair))) }
    else sql""

    val limit = query.paging match {
      case Some(p) => sql" limit #${p.pageLength}"
      case None => sql""
    }

    concat(concat(where,order),limit)

  }
<commit_msg>Fix empty filters<commit_after>package ch.wsl.box.model

import io.circe._
import ch.wsl.box.rest.utils.JSONSupport._
import geotrellis.vector.io.json.Implicits._
import Light._
import slick.dbio.DBIO
import ch.wsl.box.jdbc.PostgresProfile.api._
import ch.wsl.box.model.boxentities.BoxSchema
import ch.wsl.box.model.shared.{Filter, JSONQuery, JSONQueryFilter, JSONSort}
import ch.wsl.box.rest.runtime.Registry
import ch.wsl.box.shared.utils.DateTimeFormatters
import org.locationtech.jts.geom.{Geometry, GeometryFactory}
import slick.jdbc.{PositionedParameters, SQLActionBuilder, SetParameter}

import java.util.{Base64, UUID}
import scala.concurrent.ExecutionContext
import scala.util.Try

trait UpdateTable[T] { t:Table[T] =>
  protected def doUpdateReturning(fields:Map[String,Json],where:SQLActionBuilder):DBIO[T]
  protected def doSelectLight(where:SQLActionBuilder):DBIO[Seq[T]]

  private def orderBlock(order:JSONSort):SQLActionBuilder = sql" #${order.column} #${order.order} "

  protected def whereBuilder(query: JSONQuery): SQLActionBuilder = {
    val kv = jsonQueryComposer(this)
    val nonEmpltyFilters = query.filter.filter(f => f.value.nonEmpty || f.operator.exists(op => Seq(Filter.IS_NULL,Filter.IS_NOT_NULL).contains(op)))
    val where = if(nonEmpltyFilters.nonEmpty) {
      val filters = nonEmpltyFilters.flatMap(kv)
      filters.tail.foldLeft(concat(sql" where ", filters.head)) { case (builder, pair) => concat(builder, concat(sql" and ", pair)) }
    } else sql""

    val order = if(query.sort.nonEmpty)
      query.sort.tail.foldLeft(concat(sql" order by ", orderBlock(query.sort.head))) { case (builder, pair) => concat(builder, concat(sql" , ", orderBlock(pair))) }
    else sql""

    val limit = query.paging match {
      case Some(p) => sql" limit #${p.pageLength}"
      case None => sql""
    }

    concat(concat(where,order),limit)

  }

{'fraction_non_alphanumeric': 0.13565459610027855, 'fraction_numerical': 0.0011142061281337048, 'mean_word_length': 4.886885245901639, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3398757', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1194, 'n_words': 224}