暑假更新
This commit is contained in:
parent
ce889c6057
commit
bc796b7885
|
|
@ -13,8 +13,8 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn
|
||||||
* 1.实现接口或者继承类
|
* 1.实现接口或者继承类
|
||||||
* 2.重写相应的方法
|
* 2.重写相应的方法
|
||||||
* 3.打包
|
* 3.打包
|
||||||
*
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* 自定义UDF函数类
|
* 自定义UDF函数类
|
||||||
* 继承Hive提供的GenericUDF类
|
* 继承Hive提供的GenericUDF类
|
||||||
*/
|
*/
|
||||||
|
|
@ -22,6 +22,7 @@ public class CalStringLengthUDF extends GenericUDF {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化方法
|
* 初始化方法
|
||||||
|
*
|
||||||
* @param objectInspectors 传入到函数中的参数对应的类型的鉴别器对象
|
* @param objectInspectors 传入到函数中的参数对应的类型的鉴别器对象
|
||||||
* @return 指定函数的返回值类型对象的鉴别器对象
|
* @return 指定函数的返回值类型对象的鉴别器对象
|
||||||
* @throws UDFArgumentException
|
* @throws UDFArgumentException
|
||||||
|
|
@ -34,7 +35,7 @@ public class CalStringLengthUDF extends GenericUDF {
|
||||||
}
|
}
|
||||||
//2.校验函数的参数类型,getCategory()返回的是传入的类型,PRIMITIVE表示基本类型
|
//2.校验函数的参数类型,getCategory()返回的是传入的类型,PRIMITIVE表示基本类型
|
||||||
if (!objectInspectors[0].getCategory().equals(ObjectInspector.Category.PRIMITIVE)) {
|
if (!objectInspectors[0].getCategory().equals(ObjectInspector.Category.PRIMITIVE)) {
|
||||||
throw new UDFArgumentTypeException(0,"磺酸钠会参数类型不正确");
|
throw new UDFArgumentTypeException(0, "函数的参数类型不正确");
|
||||||
}
|
}
|
||||||
//3.返回函数的返回值类型对应的鉴别器类型
|
//3.返回函数的返回值类型对应的鉴别器类型
|
||||||
return PrimitiveObjectInspectorFactory.javaIntObjectInspector;
|
return PrimitiveObjectInspectorFactory.javaIntObjectInspector;
|
||||||
|
|
@ -42,6 +43,7 @@ public class CalStringLengthUDF extends GenericUDF {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 函数核心处理方法
|
* 函数核心处理方法
|
||||||
|
*
|
||||||
* @param deferredObjects 传入到函数的参数
|
* @param deferredObjects 传入到函数的参数
|
||||||
* @return 函数的返回值
|
* @return 函数的返回值
|
||||||
* @throws HiveException
|
* @throws HiveException
|
||||||
|
|
@ -58,6 +60,7 @@ public class CalStringLengthUDF extends GenericUDF {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于以后sql函数需要显示哪些内容
|
* 用于以后sql函数需要显示哪些内容
|
||||||
|
*
|
||||||
* @param strings
|
* @param strings
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,10 @@ object Spark010_RDD_Operator_Transform {
|
||||||
//(null.null) =>null null
|
//(null.null) =>null null
|
||||||
//(1,null) =>1
|
//(1,null) =>1
|
||||||
val rdd1: RDD[Int] = rdd.distinct()
|
val rdd1: RDD[Int] = rdd.distinct()
|
||||||
|
val rdd2=rdd.map(x=>(x,null)).reduceByKey((x, _) => x, 7)
|
||||||
rdd1.collect().foreach(println(_))
|
rdd1.collect().foreach(println(_))
|
||||||
|
println("==========================")
|
||||||
|
rdd2.collect().foreach(println(_))
|
||||||
|
|
||||||
sc.stop()
|
sc.stop()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,27 @@ object Spark01_RDD_Operator_Transform_Par {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
mapRDD1.collect()
|
mapRDD1.collect()
|
||||||
|
/*
|
||||||
|
结果:
|
||||||
|
>>>>>>1
|
||||||
|
>>>>>>3
|
||||||
|
######1
|
||||||
|
######3
|
||||||
|
>>>>>>2
|
||||||
|
######2
|
||||||
|
>>>>>>4
|
||||||
|
######4
|
||||||
|
第二次:
|
||||||
|
>>>>>>3
|
||||||
|
>>>>>>1
|
||||||
|
######1
|
||||||
|
######3
|
||||||
|
>>>>>>2
|
||||||
|
>>>>>>4
|
||||||
|
######4
|
||||||
|
######2
|
||||||
|
TODO 即分区内的1和2一定是先1后2,分区内的3和4一定是先3后4,但是1和3谁先不一定
|
||||||
|
*/
|
||||||
|
|
||||||
sc.stop()
|
sc.stop()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ object SparkStreaming11_Req1_blackList1 {
|
||||||
println(s"${day} ${user} ${ad} ${sum}")
|
println(s"${day} ${user} ${ad} ${sum}")
|
||||||
if(sum >= 30){
|
if(sum >= 30){
|
||||||
//拉入黑名单
|
//拉入黑名单
|
||||||
val conn = JDBCUtil.getConnection
|
// val conn = JDBCUtil.getConnection
|
||||||
val sql =
|
val sql =
|
||||||
"""
|
"""
|
||||||
|insert into black_list (userid) values (?)
|
|insert into black_list (userid) values (?)
|
||||||
|
|
@ -126,7 +126,7 @@ object SparkStreaming11_Req1_blackList1 {
|
||||||
//将当天的广告点击数量进行更新
|
//将当天的广告点击数量进行更新
|
||||||
//查询统计表数据
|
//查询统计表数据
|
||||||
|
|
||||||
val conn = JDBCUtil.getConnection
|
// val conn = JDBCUtil.getConnection
|
||||||
val sql =
|
val sql =
|
||||||
"""
|
"""
|
||||||
|select *
|
|select *
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,15 @@ object Scala04_Function_Normal_1 {
|
||||||
//调用时,如果不想使用默认值,直接传值即可
|
//调用时,如果不想使用默认值,直接传值即可
|
||||||
fun3("111111") //111111
|
fun3("111111") //111111
|
||||||
|
|
||||||
|
def fun4(username:String="dingjiawen",password:String="123456")={
|
||||||
|
println(s"username:$username,password:$password")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun4()
|
||||||
|
fun4(password = "qazwsx")
|
||||||
|
fun4(password = "qazwsx",username = "123")
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ object Scala05_Object_Field {
|
||||||
//而在scala中给属性提供的set,set方法不遵循bean规范,为了统一用于则有了下述写法
|
//而在scala中给属性提供的set,set方法不遵循bean规范,为了统一用于则有了下述写法
|
||||||
test.setEmail("xxx")
|
test.setEmail("xxx")
|
||||||
test.getEmail()
|
test.getEmail()
|
||||||
|
println(test.email)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ object Scala12_Object_Trait_4 {
|
||||||
trait Log extends Operator{
|
trait Log extends Operator{
|
||||||
override def operDate(): Unit ={
|
override def operDate(): Unit ={
|
||||||
print("向文件中")
|
print("向文件中")
|
||||||
super.operDate() //如果想跳过DB直接访问Operator则使用super[Operator].operDate()
|
// super[Operator].operDate() //如果想跳过DB直接访问Operator则使用super[Operator].operDate() //向文件中操作数据...
|
||||||
|
super.operDate() //如果想跳过DB直接访问Operator则使用super[Operator].operDate() //向文件中向数据库中操作数据
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class MySQL extends DB with Log {
|
class MySQL extends DB with Log {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.atguigu.scala.chapter07
|
package com.atguigu.scala.chapter07
|
||||||
|
|
||||||
|
import scala.+:
|
||||||
|
|
||||||
object Scala01_Collection_1 {
|
object Scala01_Collection_1 {
|
||||||
|
|
||||||
def main(args: Array[String]): Unit = {
|
def main(args: Array[String]): Unit = {
|
||||||
|
|
@ -27,9 +29,13 @@ object Scala01_Collection_1 {
|
||||||
|
|
||||||
//val ints1: Array[Int] = array1.:+(5)
|
//val ints1: Array[Int] = array1.:+(5)
|
||||||
val ints1 = array1 :+ 5
|
val ints1 = array1 :+ 5
|
||||||
|
val ints3 =5 +: array1
|
||||||
|
|
||||||
val ints2 = array1 ++ array3
|
val ints2 = array1 ++ array3
|
||||||
//val ints3 = array1 ++: array3
|
//val ints3 = array1 ++: array3
|
||||||
|
// println(ints)
|
||||||
|
// println(ints1)
|
||||||
|
// println(ints2)
|
||||||
|
|
||||||
println(array1 eq ints) //false
|
println(array1 eq ints) //false
|
||||||
println(array1 eq ints1) //false
|
println(array1 eq ints1) //false
|
||||||
|
|
@ -38,9 +44,9 @@ object Scala01_Collection_1 {
|
||||||
|
|
||||||
// 遍历
|
// 遍历
|
||||||
//把集合中的元素用逗号分割形成一个字符串
|
//把集合中的元素用逗号分割形成一个字符串
|
||||||
// println(ints.mkString(",")) //5,1,2,3,4
|
println(ints.mkString(",")) //5,1,2,3,4
|
||||||
// println(ints1.mkString(",")) //1,2,3,4,5
|
println(ints1.mkString(",")) //1,2,3,4,5
|
||||||
// println(ints2.mkString(",")) //1,2,3,4,5,6,7,8
|
println(ints2.mkString(",")) //1,2,3,4,5,6,7,8
|
||||||
|
|
||||||
//foreach方法是一个循环的方法,需要穿第一个函数,这个传参数的类型是函数类型
|
//foreach方法是一个循环的方法,需要穿第一个函数,这个传参数的类型是函数类型
|
||||||
// 函数类型 : Int => U
|
// 函数类型 : Int => U
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ object Scala06_Collection_Seq_2 {
|
||||||
// println(list) //ListBuffer(5, 3, 4, 2, 1)
|
// println(list) //ListBuffer(5, 3, 4, 2, 1)
|
||||||
//
|
//
|
||||||
// list.remove(1)
|
// list.remove(1)
|
||||||
// list.remove(1,2)
|
println(list)
|
||||||
|
println(list.remove(1,2))
|
||||||
//
|
//
|
||||||
// list.mkString()
|
// list.mkString()
|
||||||
// list.iterator
|
// list.iterator
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ object Scala01_Transform {
|
||||||
}
|
}
|
||||||
|
|
||||||
val age :Int = thirdPart() //Double ? Int?
|
val age :Int = thirdPart() //Double ? Int?
|
||||||
println(age)
|
println(age.isInstanceOf[Double])
|
||||||
|
|
||||||
}
|
}
|
||||||
def thirdPart(): Double ={
|
def thirdPart(): Double ={
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ package com.atguigu.scala.test;
|
||||||
public class TestAdd {
|
public class TestAdd {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//int i=0;
|
int i=0;
|
||||||
// int j=i++;
|
// int j=i++;
|
||||||
//赋值是 等号右边的计算结果给左边
|
//赋值是 等号右边的计算结果给左边
|
||||||
//i++不是原子性操作,中间会有临时的结果
|
//i++不是原子性操作,中间会有临时的结果
|
||||||
//i=i++; //print之后是1 _tmp=0; i=1; i=_tmp=0
|
i=i++; //print之后是1 _tmp=0; i=1; i=_tmp=0
|
||||||
|
|
||||||
//System.out.println("i="+i); // 1
|
System.out.println("i="+i); // 1
|
||||||
// System.out.println("j="+j); // 0
|
// System.out.println("j="+j); // 0
|
||||||
|
|
||||||
//TODO 阶乘:一个大于1的数的阶乘等于这个数乘以他减一的数的阶乘
|
//TODO 阶乘:一个大于1的数的阶乘等于这个数乘以他减一的数的阶乘
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.atguigu.scala.test;
|
||||||
|
|
||||||
//import com.atguigu.scala.chapter09.Scala02_Exception;
|
//import com.atguigu.scala.chapter09.Scala02_Exception;
|
||||||
|
|
||||||
|
import com.atguigu.scala.chapter09.Scala02_Exception;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
|
|
@ -38,7 +40,7 @@ public class TestException {
|
||||||
// }
|
// }
|
||||||
// System.out.println("xxxxxx");
|
// System.out.println("xxxxxx");
|
||||||
|
|
||||||
// Scala02_Exception.test();
|
Scala02_Exception.test();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,6 @@ object ToBitmapApp {
|
||||||
ClickhouseUtils.executeSql(clearSQL)
|
ClickhouseUtils.executeSql(clearSQL)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (tagList.size > 0) {
|
if (tagList.size > 0) {
|
||||||
//('gender',gender),('agegroup',agegroup),('favor',favor)
|
//('gender',gender),('agegroup',agegroup),('favor',favor)
|
||||||
val tagCodeSQL: String = tagList.map(
|
val tagCodeSQL: String = tagList.map(
|
||||||
|
|
@ -113,7 +112,6 @@ object ToBitmapApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ public class ZooKeeperTest {
|
||||||
* @throws KeeperException
|
* @throws KeeperException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void deleteAll(String path,ZooKeeper zk) throws KeeperException, InterruptedException {
|
public void deleteAll(String path,ZooKeeper zk) throws KeeperException, InterruptedException {
|
||||||
|
|
||||||
//判断当前节点是否存在,获取stat
|
//判断当前节点是否存在,获取stat
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
<artifactId>spring_aop</artifactId>
|
<artifactId>spring_aop</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue