Skip to content

Commit

Permalink
Refine for spotbugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tobegit3hub committed Jul 28, 2021
1 parent ea5160d commit 8f2efdd
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public static String readConf(String path) throws Exception{
InputStreamReader isr = new InputStreamReader(is, "utf-8");
reader = new BufferedReader(isr);
}else {
reader = new BufferedReader(new FileReader(path));
InputStream inputStream = new FileInputStream(path);
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
}
StringBuilder builder = new StringBuilder();
String line = reader.readLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com._4paradigm.openmldb.batch.utils;

import com.google.gson.*;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand All @@ -41,7 +44,6 @@ public static SparkConfig parseFeconfigJsonPath(String json) {

public static SparkConfig parseFeconfigJson(String json) {
logger.info("fesql config: {}", json);
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonObject jsonElement = parser.parse(json).getAsJsonObject();
SparkConfig config = new SparkConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ class NativeBufferPool {
managed
}


def freeAll(): Unit = {
allocated.values.foreach(buf => buf.free())
allocated.clear()
}

case class IndexedBuffer(id: Long, buffer: ByteBuffer) {
def getSize: Int = buffer.capacity()
}

case class IndexedBuffer(id: Long, buffer: ByteBuffer) {
def getSize: Int = buffer.capacity()

def free(): Unit = {
buffer.asInstanceOf[DirectBuffer].cleaner().clean()
}
def free(): Unit = {
buffer.asInstanceOf[DirectBuffer].cleaner().clean()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ class SparkRowCodec(sliceSchemas: Array[StructType]) {
output(fieldOffset) = new Timestamp(rowView.GetTimestampUnsafe(i))
case DateType =>
val days = rowView.GetDateUnsafe(i)
output(fieldOffset) = new Date(rowView.GetYearUnsafe(days) - 1900,
rowView.GetMonthUnsafe(days) - 1, rowView.GetDayUnsafe(days))
val calendar = Calendar.getInstance()
calendar.set(Calendar.YEAR, rowView.GetYearUnsafe(days))
calendar.set(Calendar.MONTH, rowView.GetMonthUnsafe(days))
calendar.set(Calendar.DAY_OF_MONTH, rowView.GetDayUnsafe(days))
output(fieldOffset) = calendar.getTime

case _ => throw new IllegalArgumentException(
s"Spark type ${field.dataType} not supported")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com._4paradigm.openmldb.batch.tools

import java.io.{File, FileWriter}
import java.io.{File, FileOutputStream, FileWriter, OutputStreamWriter}

import com._4paradigm.openmldb.batch.OpenmldbBatchConfig
import com._4paradigm.openmldb.batch.utils.{ArgumentParser, JmhHelper}
Expand Down Expand Up @@ -67,16 +67,24 @@ class BenchmarkWindowSampleImpl {
case "--samplePath" => samplePath = parser.parseValue()
case "--sampleIdx" => sampleIdx = parser.parseInt()
case "--resetWindow" => resetWindow = true
case _ =>
}
if (samplePath.isEmpty) {
throw new IllegalArgumentException("sample path is empty")
}
}

def saveArgs(args: Array[String]): Unit = {
val writer = new FileWriter(new File("./window_sample_bm_args.log"))
writer.write(args.mkString("\n"))
writer.close()
var writer: OutputStreamWriter = null
try {
val filePath = "./window_sample_bm_args.log"
writer = new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8")
writer.write(args.mkString("\n"))
} finally {
if (writer != null) {
writer.close()
}
}
}

def loadArgs(): Array[String] = {
Expand Down
Binary file not shown.

0 comments on commit 8f2efdd

Please sign in to comment.