<commit_before>package net.fwbrasil.activate.storage.relational.idiom

import scala.collection.immutable.Stream.Empty
import scala.collection.mutable.{ Map => MutableMap }
import net.fwbrasil.activate.storage.marshalling.BooleanStorageValue
import net.fwbrasil.activate.storage.marshalling.DoubleStorageValue
import net.fwbrasil.activate.storage.marshalling.IntStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageRenameTable
import net.fwbrasil.activate.storage.marshalling.StorageRemoveTable
import net.fwbrasil.activate.storage.marshalling.BigDecimalStorageValue
import net.fwbrasil.activate.storage.marshalling.LongStorageValue
import net.fwbrasil.activate.storage.marshalling.StringStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageValue
import net.fwbrasil.activate.storage.marshalling.DateStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageAddColumn
import net.fwbrasil.activate.storage.marshalling.ModifyStorageAction
import net.fwbrasil.activate.storage.marshalling.FloatStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageAddIndex
import net.fwbrasil.activate.storage.marshalling.StorageAddReference
import net.fwbrasil.activate.storage.marshalling.ReferenceStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageRenameColumn
import net.fwbrasil.activate.storage.marshalling.StorageCreateTable
import net.fwbrasil.activate.storage.marshalling.StorageRemoveReference
import net.fwbrasil.activate.storage.marshalling.StorageRemoveColumn
import net.fwbrasil.activate.storage.marshalling.ByteArrayStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageRemoveIndex
import net.fwbrasil.activate.storage.marshalling.ListStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageCreateListTable
import net.fwbrasil.activate.storage.marshalling.StorageRemoveListTable
import net.fwbrasil.activate.storage.marshalling.IntStorageValue
import net.fwbrasil.activate.statement.query.OrderByCriteria
import net.fwbrasil.activate.statement.query.orderByAscendingDirection
import net.fwbrasil.activate.storage.marshalling.StorageModifyColumnType

object redshiftDialect extends redshiftDialect(pEscape = string => "\"" + string + "\"", pNormalize = string => string.toLowerCase) {
  def apply(escape: String => String = string => "\"" + string + "\"", normalize: String => String = string => string.toLowerCase) =
    new redshiftDialect(escape, normalize)
}

class redshiftDialect(pEscape: String => String, pNormalize: String => String) extends postgresqlDialect (pEscape = string => "\"" + string + "\"", pNormalize = string => string) {

  override def escape(string: String) =
    pEscape(pNormalize(string))


  override def findTableStatement(tableName: String) =
    "SELECT COUNT(1) " +
      "  FROM INFORMATION_SCHEMA.TABLES " +
      " WHERE TABLE_SCHEMA = CURRENT_SCHEMA() " +
      "   AND TABLE_NAME = '" + pNormalize(tableName) + "'"

  override def findTableColumnStatement(tableName: String, columnName: String) =
    "SELECT COUNT(1) " +
      "  FROM INFORMATION_SCHEMA.COLUMNS " +
      " WHERE TABLE_SCHEMA = CURRENT_SCHEMA() " +
      "   AND TABLE_NAME = '" + pNormalize(tableName) + "'" +
      "   AND COLUMN_NAME = '" + pNormalize(columnName) + "'"

  override def findIndexStatement(tableName: String, indexName: String) =
    "SELECT COUNT(1)  " +
      "	FROM pg_catalog.pg_indexes" +
      "  WHERE schemaname = CURRENT_SCHEMA()" +
      "	AND tablename = '" + pNormalize(tableName) + "'" +
      "	AND indexname = '" + pNormalize(indexName) + "'"

  override def findConstraintStatement(tableName: String, constraintName: String): String =
    "SELECT COUNT(1) " +
      "  FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE " +
      " WHERE TABLE_SCHEMA = CURRENT_SCHEMA() " +
      "   AND TABLE_NAME = '" + pNormalize(tableName) + "'" +
      "   AND CONSTRAINT_NAME = '" + pNormalize(constraintName) + "'"

  override def toSqlDdl(action: ModifyStorageAction): String = {
    action match {
      case StorageRemoveListTable(listTableName, ifNotExists) =>
        "DROP TABLE " + escape(listTableName)
      case StorageCreateListTable(ownerTableName, ownerIdColumn, listTableName, valueColumn, orderColumn, ifNotExists) =>
        "CREATE TABLE " + escape(listTableName) + "(\n" +
          "	" + escape("owner") + " " + columnType(ownerIdColumn) + " REFERENCES " + escape(ownerTableName) + "(ID),\n" +
          toSqlDdl(valueColumn) + ", " + toSqlDdl(orderColumn) +<commit_msg>- remove constraints and index verification with "select(1)" because the  redshift dont use this types<commit_after>package net.fwbrasil.activate.storage.relational.idiom

import scala.collection.immutable.Stream.Empty
import scala.collection.mutable.{ Map => MutableMap }
import net.fwbrasil.activate.storage.marshalling.BooleanStorageValue
import net.fwbrasil.activate.storage.marshalling.DoubleStorageValue
import net.fwbrasil.activate.storage.marshalling.IntStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageRenameTable
import net.fwbrasil.activate.storage.marshalling.StorageRemoveTable
import net.fwbrasil.activate.storage.marshalling.BigDecimalStorageValue
import net.fwbrasil.activate.storage.marshalling.LongStorageValue
import net.fwbrasil.activate.storage.marshalling.StringStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageValue
import net.fwbrasil.activate.storage.marshalling.DateStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageAddColumn
import net.fwbrasil.activate.storage.marshalling.ModifyStorageAction
import net.fwbrasil.activate.storage.marshalling.FloatStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageAddIndex
import net.fwbrasil.activate.storage.marshalling.StorageAddReference
import net.fwbrasil.activate.storage.marshalling.ReferenceStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageRenameColumn
import net.fwbrasil.activate.storage.marshalling.StorageCreateTable
import net.fwbrasil.activate.storage.marshalling.StorageRemoveReference
import net.fwbrasil.activate.storage.marshalling.StorageRemoveColumn
import net.fwbrasil.activate.storage.marshalling.ByteArrayStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageRemoveIndex
import net.fwbrasil.activate.storage.marshalling.ListStorageValue
import net.fwbrasil.activate.storage.marshalling.StorageCreateListTable
import net.fwbrasil.activate.storage.marshalling.StorageRemoveListTable
import net.fwbrasil.activate.storage.marshalling.IntStorageValue
import net.fwbrasil.activate.statement.query.OrderByCriteria
import net.fwbrasil.activate.statement.query.orderByAscendingDirection
import net.fwbrasil.activate.storage.marshalling.StorageModifyColumnType

object redshiftDialect extends redshiftDialect(pEscape = string => "\"" + string + "\"", pNormalize = string => string.toLowerCase) {
  def apply(escape: String => String = string => "\"" + string + "\"", normalize: String => String = string => string.toLowerCase) =
    new redshiftDialect(escape, normalize)
}

class redshiftDialect(pEscape: String => String, pNormalize: String => String) extends postgresqlDialect (pEscape = string => "\"" + string + "\"", pNormalize = string => string) {

  override def escape(string: String) =
    pEscape(pNormalize(string))



  //dont exists index
  override def findIndexStatement(tableName: String, indexName: String) =
    "SELECT COUNT(1)  "
  //dont exists constraints
  override def findConstraintStatement(tableName: String, constraintName: String): String =
    "SELECT COUNT(1) "


  override def toSqlDdl(action: ModifyStorageAction): String = {
    action match {
      case StorageRemoveListTable(listTableName, ifNotExists) =>
        "DROP TABLE " + escape(listTableName)
      case StorageCreateListTable(ownerTableName, ownerIdColumn, listTableName, valueColumn, orderColumn, ifNotExists) =>
        "CREATE TABLE " + escape(listTableName) + "(\n" +
          "	" + escape("owner") + " " + columnType(ownerIdColumn) + " REFERENCES " + escape(ownerTableName) + "(ID),\n" +
          toSqlDdl(valueColumn) + ", " + toSqlDdl(orderColumn) +
{'fraction_non_alphanumeric': 0.10386266094420601, 'fraction_numerical': 0.0008583690987124463, 'mean_word_length': 5.556270096463023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '5401185', 'n_tokens_mistral': 2434, 'n_tokens_neox': 2404, 'n_words': 389}