<commit_before>{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}

module Control.Distributed.Spark.SQL.DataType where

import Data.Text (Text)
import Foreign.JNI
import qualified Foreign.JNI.String as JNI
import Language.Java

newtype DataType = DataType (J ('Class "org.apache.spark.sql.types.DataType"))
  deriving Eq
instance Coercible DataType ('Class "org.apache.spark.sql.types.DataType")

staticDataType :: JNI.String -> IO DataType
staticDataType dname = do
    jclass <- findClass "org/apache/spark/sql/types/DataTypes"
    jfield <- getStaticFieldID jclass dname
      (signature (sing :: Sing ('Class "org.apache.spark.sql.types.DataType")))
    DataType . unsafeCast <$> getStaticObjectField jclass jfield

doubleType :: IO DataType
doubleType = staticDataType "DoubleType"

booleanType :: IO DataType
booleanType = staticDataType "BooleanType"

longType :: IO DataType
longType = staticDataType "LongType"

stringType :: IO DataType
stringType = staticDataType "StringType"

typeName :: DataType -> IO Text
typeName dt = call dt "typeName" [] >>= reify<commit_msg>Adapt to new type of findClass.<commit_after>{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}

module Control.Distributed.Spark.SQL.DataType where

import Data.Text (Text)
import Foreign.JNI
import qualified Foreign.JNI.String as JNI
import Language.Java

newtype DataType = DataType (J ('Class "org.apache.spark.sql.types.DataType"))
  deriving Eq
instance Coercible DataType ('Class "org.apache.spark.sql.types.DataType")

staticDataType :: JNI.String -> IO DataType
staticDataType dname = do
    jclass <- findClass (referenceTypeName (SClass "org.apache.spark.sql.types.DataTypes"))
    jfield <- getStaticFieldID jclass dname
      (signature (sing :: Sing ('Class "org.apache.spark.sql.types.DataType")))
    DataType . unsafeCast <$> getStaticObjectField jclass jfield

doubleType :: IO DataType
doubleType = staticDataType "DoubleType"

booleanType :: IO DataType
booleanType = staticDataType "BooleanType"

longType :: IO DataType
longType = staticDataType "LongType"

stringType :: IO DataType
stringType = staticDataType "StringType"

typeName :: DataType -> IO Text
typeName dt = call dt "typeName" [] >>= reify
{'fraction_non_alphanumeric': 0.11167298777918247, 'fraction_numerical': 0.0, 'mean_word_length': 4.949874686716792, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '2881246', 'n_tokens_mistral': 739, 'n_tokens_neox': 744, 'n_words': 196}