Tool to transform OLTP database schemas to OLAP database schemas automatically
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArgParser.hs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. {-# LANGUAGE OverloadedStrings #-}
  2. {-# LANGUAGE RecordWildCards #-}
  3. module Ringo.ArgParser (ProgArgs(..), parseArgs) where
  4. import qualified Data.Text as Text
  5. import Data.List (intercalate)
  6. import Data.Monoid ((<>))
  7. import Options.Applicative
  8. import System.Environment (getProgName)
  9. import Ringo.Types
  10. data ProgArgs = ProgArgs
  11. { progSettings :: Settings
  12. , progInputFile :: FilePath
  13. , progOutputDir :: FilePath
  14. } deriving (Eq, Show)
  15. textOption :: Mod OptionFields String -> Parser Text.Text
  16. textOption o = Text.pack <$> strOption o
  17. settingsParser :: Parser Settings
  18. settingsParser = let Settings {..} = defSettings
  19. in Settings
  20. <$> textOption (long "dim-prefix"
  21. <> short 'd'
  22. <> value (Text.unpack settingDimPrefix)
  23. <> showDefault
  24. <> help "Prefix for dimension tables")
  25. <*> textOption (long "fact-prefix"
  26. <> short 'f'
  27. <> value (Text.unpack settingFactPrefix)
  28. <> showDefault
  29. <> help "Prefix for fact tables")
  30. <*> minorOption "fact-infix"
  31. settingFactInfix
  32. "Infix for fact tables"
  33. <*> option auto (let timeunits = map show [Second ..]
  34. in long "timeunit"
  35. <> short 't'
  36. <> value settingTimeUnit
  37. <> showDefault
  38. <> completeWith timeunits
  39. <> help ("Time unit granularity for fact tables. Possible values: "
  40. ++ intercalate ", " timeunits))
  41. <*> minorOption "avg-count-col-suffix"
  42. settingAvgCountColumnSuffix
  43. "Suffix for average count columns"
  44. <*> minorOption "avg-sum-col-suffix"
  45. settingAvgSumColumnSuffix
  46. "Suffix for average sum columns"
  47. <*> minorOption "dim-id-col-name"
  48. settingDimTableIdColumnName
  49. "Name of dimension table id columns"
  50. <*> minorOption "dim-id-col-type"
  51. settingDimTableIdColumnType
  52. "Type of dimension table id columns"
  53. <*> minorOption "fact-count-col-type"
  54. settingFactCountColumnType
  55. "Type of fact table count columns"
  56. <*> option auto (long "fact-count-distinct-error-rate"
  57. <> hidden
  58. <> value settingFactCountDistinctErrorRate
  59. <> showDefault
  60. <> help "Error rate for count distinct calulations")
  61. <*> minorOption "dependencies-json-file"
  62. settingDependenciesJSONFileName
  63. "Name of the output dependencies json file"
  64. <*> minorOption "facts-json-file"
  65. settingFactsJSONFileName
  66. "Name of the output facts json file"
  67. <*> minorOption "dimensions-json-file"
  68. settingDimensionsJSONFileName
  69. "Name of the output dimensions json file"
  70. <*> option auto (long "foreign-key-id-coalesce-val"
  71. <> hidden
  72. <> value settingForeignKeyIdCoalesceValue
  73. <> showDefault
  74. <> help "Value to coalease missing foriegn key ids to, in fact tables")
  75. <*> minorOption "tablename-suffix-template"
  76. settingTableNameSuffixTemplate
  77. "Suffix template for table names in SQL"
  78. where
  79. minorOption longDesc defValue helpTxt =
  80. textOption (long longDesc
  81. <> hidden
  82. <> value (Text.unpack defValue)
  83. <> showDefault
  84. <> help helpTxt)
  85. progArgsParser :: Parser ProgArgs
  86. progArgsParser =
  87. ProgArgs
  88. <$> settingsParser
  89. <*> argument str (metavar "INPUT"
  90. <> action "file"
  91. <> help "Input file")
  92. <*> argument str (metavar "OUTPUT"
  93. <> action "directory"
  94. <> help "Output directory")
  95. versionParser :: String -> Parser (a -> a)
  96. versionParser progName = infoOption (progName ++ " " ++ version)
  97. (long "version"
  98. <> short 'v'
  99. <> help "Print version information")
  100. where
  101. version = "0.1.0"
  102. parseArgs :: IO ProgArgs
  103. parseArgs = do
  104. progName <- getProgName
  105. execParser $
  106. info (helper <*> versionParser progName <*> progArgsParser)
  107. (fullDesc
  108. <> progDesc "Tool to transform Postgres OLTP schemas to OLAP star schemas automatically"
  109. <> header (progName ++ " - OLTP to OLAP schema transformer for Postgres")
  110. <> footer "© 2015-2017 Quintype Inc, Nilenso Software LLP, Abhinav Sarkar. http://github.com/abhin4v/ringo")