Skip to content

Commit

Permalink
#1807 format log
Browse files Browse the repository at this point in the history
  • Loading branch information
wangcheng15 committed Aug 10, 2022
1 parent 783d1f8 commit 240195e
Show file tree
Hide file tree
Showing 72 changed files with 590 additions and 224 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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}
Expand Down Expand Up @@ -36,7 +35,11 @@ class RDSchema(dbType: String) {
try {
f.toString.toInt
} catch {
case e: Exception => 0
case e: Exception =>
// if (log.isDebugEnabled()) {
// log.debug("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())
if (log.isInfoEnabled()) {
log.info("=======")
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,9 @@ class RestIndexerMeta(url: String, token: String,timeout:Int=2000) extends MLSQL
JSONTool.parseJson[Map[MlsqlOriTable, List[MlsqlIndexerItem]]](value)
} catch {
case e: Exception =>
e.printStackTrace()
if (log.isDebugEnabled) {
log.debug("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
@@ -1,12 +1,13 @@
package tech.mlsql.test.tool

import org.scalatest.{BeforeAndAfterAll, FunSuite}
import tech.mlsql.common.utils.log.Logging
import tech.mlsql.tool.ZOrderingBytesUtil

/**
* 31/12/2020 WilliamZhu([email protected])
*/
class ByteUtilTest extends FunSuite with BeforeAndAfterAll {
class ByteUtilTest extends FunSuite with BeforeAndAfterAll with Logging{
test("toString") {
//只需要支持证正数
val a = 3L
Expand All @@ -18,7 +19,9 @@ class ByteUtilTest extends FunSuite with BeforeAndAfterAll {
}

test("func"){
println(ZOrderingBytesUtil.toString(ZOrderingBytesUtil.toBytes(-1)))
if (log.isDebugEnabled()) {
log.info(ZOrderingBytesUtil.toString(ZOrderingBytesUtil.toBytes(-1)))
}
}

test("intTo8Byte") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

package tech.mlsql.cluster.service.elastic_resource

import org.slf4j.LoggerFactory

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

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

Expand Down Expand Up @@ -65,7 +66,9 @@ object AllocateService extends Logging {
}
} catch {
case e: Exception =>
e.printStackTrace()
if (logger.isDebugEnabled()) {
logger.debug("run Error: {}", e)
}
//catch all ,so the scheduler will not been stopped by exception
}
}
Expand Down
Loading

0 comments on commit 240195e

Please sign in to comment.