Skip to content

Commit

Permalink
format log
Browse files Browse the repository at this point in the history
  • Loading branch information
wangcheng15 committed Sep 26, 2022
1 parent a7f55d1 commit 1eb5065
Show file tree
Hide file tree
Showing 70 changed files with 414 additions and 272 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package tech.mlsql.autosuggest.app

import java.sql.{JDBCType, SQLException}

import com.alibaba.druid.sql.SQLUtils
import com.alibaba.druid.sql.ast.SQLDataType
import com.alibaba.druid.sql.ast.statement.{SQLColumnDefinition, SQLCreateTableStatement}
import com.alibaba.druid.sql.repository.SchemaRepository
import org.apache.spark.sql.jdbc.JdbcDialects
import org.apache.spark.sql.types.DecimalType.{MAX_PRECISION, MAX_SCALE}
import org.apache.spark.sql.types._
import org.slf4j.{Logger, LoggerFactory}

import scala.collection.JavaConverters._
import scala.math.min
Expand All @@ -18,6 +18,8 @@ import scala.math.min
*/
class RDSchema(dbType: String) {

private val log: Logger = LoggerFactory.getLogger(this.getClass)

private val repository = new SchemaRepository(dbType)

def createTable(sql: String) = {
Expand All @@ -36,7 +38,9 @@ class RDSchema(dbType: String) {
try {
f.toString.toInt
} catch {
case e: Exception => 0
case e: Exception =>
log.error("ExtractfieldSize Error: {}", e)
0
}

}.headOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import org.scalatest.BeforeAndAfterEach
import tech.mlsql.autosuggest.meta.{MetaProvider, MetaTable, MetaTableColumn, MetaTableKey}
import tech.mlsql.autosuggest.statement.{LexerUtils, SuggestItem}
import tech.mlsql.autosuggest.{DataType, SpecialTableConst, TokenPos, TokenPosType}
import tech.mlsql.common.utils.log.Logging

import scala.collection.JavaConverters._

/**
* 2/6/2020 WilliamZhu([email protected])
*/
class AutoSuggestContextTest extends BaseTest with BeforeAndAfterEach {
class AutoSuggestContextTest extends BaseTest with BeforeAndAfterEach with Logging {
override def afterEach(): Unit = {
// context.statements.clear()
}
Expand Down Expand Up @@ -44,8 +45,9 @@ class AutoSuggestContextTest extends BaseTest with BeforeAndAfterEach {

def printStatements(items: List[List[Token]]) = {
items.foreach { item =>
println(item.map(_.getText).mkString(" "))
println()
if (log.isInfoEnabled()) {
log.info(item.map(_.getText).mkString(" "))
}
}
}

Expand Down Expand Up @@ -84,7 +86,7 @@ class AutoSuggestContextTest extends BaseTest with BeforeAndAfterEach {
|SELECT CAST(25.65 AS int) from jack;
|""".stripMargin).tokens.asScala.toList

wow.foreach(item => println(s"${item.getText} ${item.getType}"))
wow.foreach(item => log.info("{} {}", item.getText, item.getType))
}

test("load/select 4/10 select ke[cursor] from") {
Expand Down Expand Up @@ -150,7 +152,9 @@ class AutoSuggestContextTest extends BaseTest with BeforeAndAfterEach {
| select from table3
|""".stripMargin).tokens.asScala.toList
val items = context.build(wow).suggest(5, 8)
println(items)
if (log.isInfoEnabled()) {
log.info(items.toString())
}

}

Expand Down Expand Up @@ -178,7 +182,9 @@ class AutoSuggestContextTest extends BaseTest with BeforeAndAfterEach {
| select sum() from table3
|""".stripMargin
val items = context.buildFromString(sql).suggest(5, 12)
println(items)
if (log.isInfoEnabled()) {
log.info(items.toString())
}

}
test("table alias with temp table") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package com.intigua.antlr4.autosuggest

import tech.mlsql.autosuggest.statement.LoadSuggester
import tech.mlsql.autosuggest.{TokenPos, TokenPosType}
import tech.mlsql.common.utils.log.Logging

import scala.collection.JavaConverters._

/**
* 2/6/2020 WilliamZhu([email protected])
*/
class LoadSuggesterTest extends BaseTest {
class LoadSuggesterTest extends BaseTest with Logging {
test("load hiv[cursor]") {
val wow = context.lexer.tokenizeNonDefaultChannel(
"""
Expand All @@ -26,7 +27,13 @@ class LoadSuggesterTest extends BaseTest {
| load
|""".stripMargin).tokens.asScala.toList
val loadSuggester = new LoadSuggester(context, wow, TokenPos(0, TokenPosType.NEXT, 0)).suggest()
println(loadSuggester)
if (log.isInfoEnabled()) {
var loadSuggesterToString = "";
loadSuggester.foreach(i =>
loadSuggesterToString += ("name: " + i.name + ",")
)
log.info(loadSuggesterToString)
}
assert(loadSuggester.size > 1)
}

Expand All @@ -37,7 +44,9 @@ class LoadSuggesterTest extends BaseTest {
| load csv.`` where
|""".stripMargin).tokens.asScala.toList
val result = new LoadSuggester(context, wow, TokenPos(4, TokenPosType.NEXT, 0)).suggest()
println(result)
if (log.isInfoEnabled()) {
log.info(result.toString())
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package com.intigua.antlr4.autosuggest
import tech.mlsql.autosuggest.meta.{MetaProvider, MetaTable, MetaTableColumn, MetaTableKey}
import tech.mlsql.autosuggest.statement.SelectSuggester
import tech.mlsql.autosuggest.{DataType, MLSQLSQLFunction, TokenPos, TokenPosType}
import tech.mlsql.common.utils.log.Logging

import scala.collection.JavaConverters._

/**
* 2/6/2020 WilliamZhu([email protected])
*/
class SelectSuggesterTest extends BaseTest {
class SelectSuggesterTest extends BaseTest with Logging {

def buildMetaProvider = {
context.setUserDefinedMetaProvider(new MetaProvider {
Expand Down Expand Up @@ -185,10 +186,14 @@ class SelectSuggesterTest extends BaseTest {
|""".stripMargin).tokens.asScala.toList

val suggester = new SelectSuggester(context, wow2, TokenPos(0, TokenPosType.NEXT, 0))
println(suggester.sqlAST.printAsStr(suggester.tokens, 0))
if (log.isInfoEnabled()) {
log.info(suggester.sqlAST.printAsStr(suggester.tokens, 0))
}
suggester.table_info.foreach { case (level, item) =>
println(level + ":")
println(item.map(_._1).toList)
if (log.isInfoEnabled()) {
log.info(level + ":")
log.info(item.map(_._1).toList.toString())
}
}
assert(suggester.suggest().map(_.name) == List(("b"), ("keywords"), ("search_num"), ("rank")))

Expand All @@ -203,8 +208,10 @@ class SelectSuggesterTest extends BaseTest {
val tokens = getMLSQLTokens(sql)

val suggester = new SelectSuggester(context, tokens, TokenPos(0, TokenPosType.NEXT, 0))
println("=======")
println(suggester.suggest())
log.info("=======")
if (log.isInfoEnabled()) {
log.info(suggester.suggest().toString())
}
assert(suggester.suggest().head.name=="b")
}

Expand Down Expand Up @@ -250,7 +257,9 @@ class SelectSuggesterTest extends BaseTest {
|""".stripMargin).tokens.asScala.toList

val suggester = new SelectSuggester(context, wow, TokenPos(1, TokenPosType.CURRENT, 3))
println(suggester.suggest())
if (log.isInfoEnabled()) {
log.info(suggester.suggest().toString())
}
assert(suggester.suggest().map(_.name) == List(("split")))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class TableStructureTest extends BaseTest with Logging {
val tokens = getMLSQLTokens(sql)

val suggester = new SelectSuggester(context, tokens, TokenPos(0, TokenPosType.NEXT, 0))
println(suggester.sqlAST)
if (log.isInfoEnabled()) {
log.info(suggester.toString)
}
}

test("s2") {
Expand Down Expand Up @@ -82,7 +84,9 @@ class TableStructureTest extends BaseTest with Logging {
val suggester = new SelectSuggester(context, wow, TokenPos(3, TokenPosType.CURRENT, 1))
val root = suggester.sqlAST
root.visitDown(0) { case (ast, level) =>
println(s"${ast.name(suggester.tokens)} ${ast.output(suggester.tokens)}")
if (log.isInfoEnabled()) {
log.info("{} {}", ast.name(suggester.tokens), ast.output(suggester.tokens))
}
}

assert(suggester.suggest().map(_.name) == List("keywords"))
Expand All @@ -99,7 +103,9 @@ class TableStructureTest extends BaseTest with Logging {
val suggester = new SelectSuggester(context, wow, TokenPos(3, TokenPosType.CURRENT, 1))
val root = suggester.sqlAST
root.visitDown(0) { case (ast, level) =>
println(s"${ast.name(suggester.tokens)} ${ast.output(suggester.tokens)}")
if (log.isInfoEnabled()) {
log.info("{} {}", ast.name(suggester.tokens), ast.output(suggester.tokens))
}
}

assert(suggester.suggest().map(_.name) == List("keywords"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import streaming.dsl.ScriptSQLExec
import streaming.dsl.auth._
import streaming.dsl.mmlib.SQLAlg
import streaming.dsl.mmlib.algs.param.WowParams
import tech.mlsql.common.utils.log.Logging
import tech.mlsql.common.utils.serder.json.JSONTool
import tech.mlsql.dsl.auth.ETAuth
import tech.mlsql.dsl.auth.dsl.mmlib.ETMethod.ETMethod

/**
* 27/3/2020 WilliamZhu([email protected])
*/
class ProfilerCommand(override val uid: String) extends SQLAlg with ETAuth with WowParams {
class ProfilerCommand(override val uid: String) extends SQLAlg with ETAuth with WowParams with Logging {
def this() = this(WowParams.randomUID())

override def train(df: DataFrame, path: String, params: Map[String, String]): DataFrame = {
Expand Down Expand Up @@ -48,7 +49,9 @@ class ProfilerCommand(override val uid: String) extends SQLAlg with ETAuth with
val explain = MLSQLUtils.createExplainCommand(df.queryExecution.logical, extended = extended)
val items = df.sparkSession.sessionState.executePlan(explain).executedPlan.executeCollect().
map(_.getString(0)).mkString("\n")
println(items)
if (log.isInfoEnabled()) {
log.info(items)
}
df.sparkSession.createDataset[Plan](Seq(Plan("doc", items))).toDF()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package tech.mlsql.indexer.impl

import java.nio.charset.Charset

import org.apache.http.client.fluent.{Form, Request}
import tech.mlsql.common.utils.log.Logging
import tech.mlsql.common.utils.serder.json.JSONTool
import tech.mlsql.indexer.{MLSQLIndexerMeta, MlsqlIndexerItem, MlsqlOriTable}

/**
* 21/12/2020 WilliamZhu([email protected])
*/
class RestIndexerMeta(url: String, token: String,timeout:Int=2000) extends MLSQLIndexerMeta {
class RestIndexerMeta(url: String, token: String,timeout:Int=2000) extends MLSQLIndexerMeta with Logging {
override def fetchIndexers(tableNames: List[MlsqlOriTable], options: Map[String, String]): Map[MlsqlOriTable, List[MlsqlIndexerItem]] = {
val form = Form.form()
form.add("data", JSONTool.toJsonStr(tableNames))
Expand All @@ -23,7 +23,7 @@ class RestIndexerMeta(url: String, token: String,timeout:Int=2000) extends MLSQL
JSONTool.parseJson[Map[MlsqlOriTable, List[MlsqlIndexerItem]]](value)
} catch {
case e: Exception =>
e.printStackTrace()
log.error("FetchIndexers Error: {}", e)
Map()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import streaming.dsl.ScriptSQLExec
import streaming.dsl.auth._
import streaming.dsl.mmlib.SQLAlg
import streaming.dsl.mmlib.algs.param.WowParams
import tech.mlsql.common.utils.log.Logging
import tech.mlsql.common.utils.serder.json.JSONTool
import tech.mlsql.dsl.auth.ETAuth
import tech.mlsql.dsl.auth.dsl.mmlib.ETMethod.ETMethod

/**
* 27/3/2020 WilliamZhu([email protected])
*/
class ProfilerCommand(override val uid: String) extends SQLAlg with ETAuth with WowParams {
class ProfilerCommand(override val uid: String) extends SQLAlg with ETAuth with WowParams with Logging {
def this() = this(WowParams.randomUID())

override def train(df: DataFrame, path: String, params: Map[String, String]): DataFrame = {
Expand Down Expand Up @@ -48,7 +49,9 @@ class ProfilerCommand(override val uid: String) extends SQLAlg with ETAuth with
val explain = MLSQLUtils.createExplainCommand(df.queryExecution.logical, extended = extended)
val items = df.sparkSession.sessionState.executePlan(explain).executedPlan.executeCollect().
map(_.getString(0)).mkString("\n")
println(items)
if (log.isInfoEnabled()) {
log.info(items)
}
df.sparkSession.createDataset[Plan](Seq(Plan("doc", items))).toDF()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

package tech.mlsql.cluster.service.elastic_resource

import java.util.concurrent.{Executors, TimeUnit}
import java.util.logging.Logger
import org.slf4j.LoggerFactory

import java.util.concurrent.{Executors, TimeUnit}
import tech.mlsql.cluster.ProxyApplication
import tech.mlsql.cluster.model.ElasticMonitor
import tech.mlsql.common.utils.log.Logging
Expand All @@ -31,7 +31,6 @@ import scala.collection.JavaConverters._
* 2018-12-05 WilliamZhu([email protected])
*/
object AllocateService extends Logging {
val logger = Logger.getLogger("AllocateService")
private[this] val _executor = Executors.newFixedThreadPool(100)
private[this] val scheduler = Executors.newSingleThreadScheduledExecutor()

Expand Down Expand Up @@ -65,7 +64,7 @@ object AllocateService extends Logging {
}
} catch {
case e: Exception =>
e.printStackTrace()
log.error("Running Error: {}", e)
//catch all ,so the scheduler will not been stopped by exception
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
package tech.mlsql.cluster.test

import java.util

import net.csdn.ServiceFramwork
import net.csdn.bootstrap.Bootstrap
import org.scalatest.{FlatSpec, Matchers}
import tech.mlsql.cluster.model.{Backend, EcsResourcePool, ElasticMonitor}
import tech.mlsql.cluster.service.elastic_resource.local.LocalDeployInstance
import tech.mlsql.cluster.service.elastic_resource.{BaseResource, JobNumAwareAllocateStrategy, LocalResourceAllocation, LocalResourceDeAllocation}
import tech.mlsql.common.utils.log.Logging

import scala.collection.JavaConverters._

/**
* 2018-12-07 WilliamZhu([email protected])
*/
class DeploySpec extends FlatSpec with Matchers {
class DeploySpec extends FlatSpec with Matchers with Logging{

def mockServer = {
try {
Expand Down Expand Up @@ -117,7 +117,9 @@ class DeploySpec extends FlatSpec with Matchers {
planRes = allocate.plan(monitor.getTag.split(",").toSeq, monitor)
assume(planRes.isDefined)

print(planRes)
if (log.isInfoEnabled()) {
log.info(planRes.toString)
}

planRes.get match {
case LocalResourceAllocation(tags) => assume(tags == "jack")
Expand Down Expand Up @@ -186,7 +188,9 @@ class DeploySpec extends FlatSpec with Matchers {
planRes = allocate.plan(monitor.getTag.split(",").toSeq, monitor)
assume(planRes.isDefined)

print(planRes)
if (log.isInfoEnabled()) {
log.info(planRes.toString)
}

planRes.get match {
case LocalResourceDeAllocation(tags) => assume(tags == "jack")
Expand Down
Loading

0 comments on commit 1eb5065

Please sign in to comment.