<commit_before>/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package water.api

import java.io.File
import java.util

import com.google.gson.{JsonObject, JsonParser}
import org.apache.spark.SparkContext
import org.apache.spark.h2o._
import org.apache.spark.h2o.util.{SparkTestContext, SharedSparkTestContext}
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.types.{StructField, DataType, Metadata, StructType}
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import water.DKV
import water.api.DataFrames._
import water.api.RDDs.{RDDsV3, RDDsHandler}
import water.fvec.{Frame, H2OFrame}

import scala.util.parsing.json.{JSONObject, JSON}

/**
 * Test suite for dataframes end-points
 */
@RunWith(classOf[JUnitRunner])
class DataFramesHandlerSuite extends FunSuite with SparkTestContext {
  sc = new SparkContext("local[*]", "test-local", conf = defaultSparkConf)
  hc = H2OContext.getOrCreate(sc)
  // Shared h2oContext
  val h2oContext = hc
  // Shared sqlContext
  SQLContext.clearActive()
  implicit val sqlContext = SQLContext.getOrCreate(sc)

  test("DataFrameHandler.list() method") {
    import sqlContext.implicits._

    val rdd = sc.parallelize(1 to 10)
    val rid = "df_" + rdd.id

    // create dataframe using method toDF, This is spark method which does not include any metadata
    val df = rdd.toDF("nums")
    df.registerTempTable(rid)
    val dataFramesHandler = new DataFramesHandler(sc,h2oContext)

    val req = new DataFramesV3
    val result = dataFramesHandler.list(3, req)
    assert (result.dataFrames.length == 1, "Number of created and persisted DataFramess should be 1")<commit_msg>Fix of previous commit<commit_after>/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package water.api

import java.io.File
import java.util

import com.google.gson.{JsonObject, JsonParser}
import org.apache.spark.SparkContext
import org.apache.spark.h2o._
import org.apache.spark.h2o.util.{SparkTestContext, SharedSparkTestContext}
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.types.{StructField, DataType, Metadata, StructType}
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import water.DKV
import water.api.DataFrames._
import water.api.RDDs.{RDDsV3, RDDsHandler}
import water.fvec.{Frame, H2OFrame}

import scala.util.parsing.json.{JSONObject, JSON}

/**
 * Test suite for dataframes end-points
 */
@RunWith(classOf[JUnitRunner])
class DataFramesHandlerSuite extends FunSuite with SparkTestContext {
  sc = new SparkContext("local[*]", "test-local", conf = defaultSparkConf)
  hc = H2OContext.getOrCreate(sc)
  // Shared h2oContext
  val h2oContext = hc
  // Shared sqlContext
  implicit val sqlContext = SQLContext.getOrCreate(sc)

  test("DataFrameHandler.list() method") {
    import sqlContext.implicits._

    val rdd = sc.parallelize(1 to 10)
    val rid = "df_" + rdd.id

    // create dataframe using method toDF, This is spark method which does not include any metadata
    val df = rdd.toDF("nums")
    df.registerTempTable(rid)
    val dataFramesHandler = new DataFramesHandler(sc,h2oContext)

    val req = new DataFramesV3
    val result = dataFramesHandler.list(3, req)
    assert (result.dataFrames.length == 1, "Number of created and persisted DataFramess should be 1")
{'fraction_non_alphanumeric': 0.08685737976782752, 'fraction_numerical': 0.007877280265339967, 'mean_word_length': 4.520594965675057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6437355', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1411, 'n_words': 487}