module Database.Sql.Presto.Type where
import Database.Sql.Type
import Database.Sql.Position (Range)
import Database.Sql.Util.Columns
import Database.Sql.Util.Joins
import Database.Sql.Util.Lineage.Table
import Database.Sql.Util.Lineage.ColumnPlus
import Database.Sql.Util.Schema
import Database.Sql.Util.Scope
import Database.Sql.Util.Tables
import Data.Aeson as JSON
import Data.Proxy (Proxy (..))
import qualified Data.Set as S
import qualified Data.Map as M
import Data.Data (Data)
import GHC.Generics (Generic)
data Presto
deriving instance Data Presto
dialectProxy :: Proxy Presto
dialectProxy = Proxy
instance Dialect Presto where
shouldCTEsShadowTables _ = True
resolveCreateTableExtra _ Unused = pure Unused
getSelectScope _ fromColumns selectionAliases = SelectScope
{ bindForWhere = bindFromColumns fromColumns
, bindForGroup = bindFromColumns fromColumns
, bindForHaving = bindFromColumns fromColumns
, bindForOrder = bindBothColumns fromColumns selectionAliases
, bindForNamedWindow = bindColumns []
}
areLcolumnsVisibleInLateralViews _ = True
data PrestoStatement r a = PrestoStandardSqlStatement (Statement Presto r a)
| PrestoUnhandledStatement a
deriving instance (ConstrainSNames Data r a, Data r) => Data (PrestoStatement r a)
deriving instance Generic (PrestoStatement r a)
deriving instance ConstrainSNames Eq r a => Eq (PrestoStatement r a)
deriving instance ConstrainSNames Show r a => Show (PrestoStatement r a)
deriving instance ConstrainSASNames Functor r => Functor (PrestoStatement r)
deriving instance ConstrainSASNames Foldable r => Foldable (PrestoStatement r)
deriving instance ConstrainSASNames Traversable r => Traversable (PrestoStatement r)
instance HasJoins (PrestoStatement ResolvedNames a) where
getJoins (PrestoStandardSqlStatement stmt) = getJoins stmt
getJoins (PrestoUnhandledStatement _) = S.empty
instance HasTableLineage (PrestoStatement ResolvedNames a) where
getTableLineage (PrestoStandardSqlStatement stmt) = tableLineage stmt
getTableLineage (PrestoUnhandledStatement _) = M.empty
instance HasColumnLineage (PrestoStatement ResolvedNames Range) where
getColumnLineage (PrestoStandardSqlStatement stmt) = columnLineage stmt
getColumnLineage (PrestoUnhandledStatement _) = returnNothing M.empty
resolvePrestoStatement :: PrestoStatement RawNames a -> Resolver (PrestoStatement ResolvedNames) a
resolvePrestoStatement (PrestoStandardSqlStatement stmt) =
PrestoStandardSqlStatement <$> resolveStatement stmt
resolvePrestoStatement (PrestoUnhandledStatement info) = pure $ PrestoUnhandledStatement info
instance HasSchemaChange (PrestoStatement ResolvedNames a) where
getSchemaChange (PrestoStandardSqlStatement stmt) = getSchemaChange stmt
getSchemaChange (PrestoUnhandledStatement _) = []
instance (ConstrainSNames ToJSON r a, ToJSON a) => ToJSON (PrestoStatement r a) where
toJSON (PrestoStandardSqlStatement stmt) = toJSON stmt
toJSON (PrestoUnhandledStatement info) = JSON.object
[ "tag" .= JSON.String "PrestoUnhandledStatement"
, "info" .= info
]
typeExample :: ()
typeExample = const () $ toJSON (undefined :: PrestoStatement ResolvedNames Range)
instance HasTables (PrestoStatement ResolvedNames a) where
goTables (PrestoStandardSqlStatement s) = goTables s
goTables (PrestoUnhandledStatement _) = return ()
instance HasColumns (PrestoStatement ResolvedNames a) where
goColumns (PrestoStandardSqlStatement s) = goColumns s
goColumns (PrestoUnhandledStatement _) = return ()