在本文中,您将会了解到关于Oracle基本知识:%TYPE和%ROWTYPE的新资讯,同时我们还将为您解释oracle中type用法的相关在本文中,我们将带你探索Oracle基本知识:%TYPE和%R
在本文中,您将会了解到关于Oracle基本知识:%TYPE 和 %ROWTYPE的新资讯,同时我们还将为您解释oracle中type用法的相关在本文中,我们将带你探索Oracle基本知识:%TYPE 和 %ROWTYPE的奥秘,分析oracle中type用法的特点,并给出一些关于Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查、c# typeof 与 Type.GetType 使用与效率对比、com.sun.tools.classfile.Type.TypeParamType的实例源码、Django TypeError: isinstance() arg 2 must be a type or tuple of types的实用技巧。
本文目录一览:- Oracle基本知识:%TYPE 和 %ROWTYPE(oracle中type用法)
- Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查
- c# typeof 与 Type.GetType 使用与效率对比
- com.sun.tools.classfile.Type.TypeParamType的实例源码
- Django TypeError: isinstance() arg 2 must be a type or tuple of types
Oracle基本知识:%TYPE 和 %ROWTYPE(oracle中type用法)
使用%TYPE
声明一个类型动态改变的变量,将该变量的类型与表的某列的类型进行动态绑定,即表列的类型改变,则该变量类型也改变。
在许多情况下,PL/SQL变量可以用来存储在数据库表中的数据。在这种情况下,变量应该拥有与表列相同的类型。例如,students表的first_name列的类型为VARCHAR2(20),我们可以按照下述方式声明一个变量:
DECLARE
v_FirstName VARCHAR2(20);
但是如果first_name列的定义改变了会发生什么(比如说表改变了,first_name现在的类型变为VARCHAR2(25))?那就会导致所有使用这个列的PL/SQL代码都必须进行修改。这时,你可以使用”%TYPE”属性而不是将变量类型硬性编码。
例如:
DECLARE
v_FirstName students.first_name%TYPE;
通过使用%TYPE,v_FirstName变量将同students表的first_name列的类型相同(可以理解为将两者邦定起来)。
2. %ROWTYPE 类似于记录
在PL/SQL中将一个记录声明为具有相同类型的数据库行。PL/SQL提供%ROWTYPE运算符实现该操作。
例如:DECLARE v_RoomRecord rooms%ROWTYPE;
定义一个记录 v_RoomRecord,该记录中的字段将与rooms表中的列相对应。
2.1 PL/SQL记录 类似一个多维数组。
PL/SQL记录类型类似于C语言中的结构,是一种复合类型,是用户自定义的。
记录提供了一种处理独立的但又作为一个整体单元相关的变量的机制。请看:
DECLARE
v_StudentID NUMBER(5);
v_FirstName VARCHAR2(20);
v_LastName VARCHAR2(20);
这3个变量在逻辑上是相互关联的,因为他们指向students表中不同的字段。如果为这些变量声明一个记录类型,那么他们之间的关系就十分明显,可作为一个单元进行处理。
DECLARE
/*Define a record type to hold common student informationi*/
TYPE t_StudentRecord IS RECORD(
StudentID NUMBER(5),
FirstName VARCHAR2(20),
LastName VARCHAR2(20);
/*Declare a variable of this type.*/
v_StudentInfo t_StudentRecord;
2.2 记录赋值
可以用SELECT语句向记录赋值,这将会从数据库中检索数据并将该数据存储到记录中。注意的是,记录中字段应该和查询结果列表中的字段相匹配。
SELECT studentID,firstName,lastName
into v_StudentInfo
from students where studentID=32;
2.3 使用%ROWTYPE
在PL/SQL中将一个记录声明为具有相同类型的数据库行的作法是很常见的。PL/SQL提供了%ROWTYPE运算符,使得这样的操作更为方便。
例如:DECLARE
v_RoomRecord rooms%ROWTYPE;
将定义一个记录,该记录中的字段将与rooms表中的列相对应。
Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查
当使用 rabbitmq 作为 airflow 的 broker 的时候,启动 scheduler,即执行 airflow scheduler 命令的时候抛出以下异常:
Traceback (most recent call last):
File "/anaconda/anaconda3/bin/airflow", line 27, in <module>
args.func(args)
File "/anaconda/anaconda3/lib/python3.6/site-packages/airflow/bin/cli.py", line 818, in scheduler
......
......
File "/anaconda/anaconda3/lib/python3.6/site-packages/kombu/connection.py", line 494, in _ensured
return fun(*args, **kwargs)
File "/anaconda/anaconda3/lib/python3.6/site-packages/kombu/messaging.py", line 203, in _publish
mandatory=mandatory, immediate=immediate,
File "/anaconda/anaconda3/lib/python3.6/site-packages/librabbitmq/__init__.py", line 122, in basic_publish
mandatory or False, immediate or False,
TypeError: an integer is required (got type NoneType)
整体环境描述:
python3.6 + apache-airflow1.9.0 + rabbitmq 3.6
因为使用 redis 作为 broker 是可以正常运行的,但是换成 rabbitmq 之后就出现了这种情况。尝试过对 rabbitmq 降版本,对 airflow 降低版本,发现依然无解,说明并不是软件版本兼容问题。
于是进一步排查,单独使用 celery4.x 进行调试,发现 celery 可以正常运行,但是到了 airflow 下就出现问题,说明是配置问题。
但是 airflow 的官方文档中配置是相当简陋的,而源码中相关的配置又相当的多,实在无法定位。于是采用最粗暴的做法,调试,但是服务器无法远程,没有外网端口,不能远程调试,而且 airflow 并不支持 windows 平台。于是只能通过日志调试:
首先,根据异常提示,说明有配置属性为空导致了这个异常,于是在异常处加上打印日志:
$ vi /anaconda/anaconda3/lib/python3.6/site-packages/librabbitmq/__init__.py
......
......
if isinstance(body, tuple):
body, properties = body
elif isinstance(body, self.Message):
body, properties = body.body, body.properties
print("---------------------------------------")
print(self.channel_id)
print("---------------------------------------")
print(body)
print("---------------------------------------")
print(exchange)
print("---------------------------------------")
print(routing_key)
print("---------------------------------------")
print(properties)
print("---------------------------------------")
print(mandatory)
print("---------------------------------------")
print(immediate)
print("---------------------------------------")
#if properties["priority"] is None: 加上这一句后就不会抛出异常了
# properties["priority"] = 0
return self.connection._basic_publish(
self.channel_id, body, exchange, routing_key, properties,
mandatory or False, immediate or False,
)
......
......
打印结果如下:
---------------------------------------
1
---------------------------------------
b''\x80\x02}q\x00(X\x04\x00\x00\x00taskq\x01X1\x00\x00\x00airflow.executors.celery_executor.execute_commandq\x02X\x02\x00\x00\x00idq\x03X$\x00\x00\x0077410b3a-75c6-4ba0-a448-7048c029e80cq\x04X\x04\x00\x00\x00argsq\x05]q\x06X\xcc\x00\x00\x00airflow run example_passing_params_via_test_command run_this 2018-07-02T01:04:00 --local -sd /anaconda/anaconda3/lib/python3.6/site-packages/airflow/example_dags/example_passing_params_via_test_command.pyq\x07aX\x06\x00\x00\x00kwargsq\x08}q\tX\x07\x00\x00\x00retriesq\nK\x00X\x03\x00\x00\x00etaq\x0bNX\x07\x00\x00\x00expiresq\x0cNX\x03\x00\x00\x00utcq\r\x88X\t\x00\x00\x00callbacksq\x0eNX\x08\x00\x00\x00errbacksq\x0fNX\t\x00\x00\x00timelimitq\x10NN\x86q\x11X\x07\x00\x00\x00tasksetq\x12NX\x05\x00\x00\x00chordq\x13Nu.''
---------------------------------------
default
---------------------------------------
celery
---------------------------------------
{''reply_to'': ''d0552f0c-b341-30b6-9edb-fa9599715d6c'', ''correlation_id'': ''77410b3a-75c6-4ba0-a448-7048c029e80c'', ''delivery_mode'': 2, ''content_type'': ''application/x-python-serialize'', ''content_encoding'': ''binary'', ''headers'': {}, ''priority'': None}
---------------------------------------
None
---------------------------------------
None
---------------------------------------
因为 mandatory 和 immediate 是 bool 类型,且都尝试过给其设置值,但是依然报错,最后还为 None 的就剩下 priority 属性为 None 了。于是尝试在代码中对其设置一个 int 类型的值,结果再次运行并无异常,说明缺少优先级属性导致了这个问题,于是可以在 priority 属性为 None 的时候给它一个默认值:
......
......
if isinstance(body, tuple):
body, properties = body
elif isinstance(body, self.Message):
body, properties = body.body, body.properties
if properties["priority"] is None: #加上这一句后就不会抛出异常了
properties["priority"] = 0
return self.connection._basic_publish(
self.channel_id, body, exchange, routing_key, properties,
mandatory or False, immediate or False,
)
......
......
后续发现这样修改源码确实不会出现之前的问题,但是会出现
TypeError can''t pickle memoryview objects
之类的异常,后确认是 librabbitmq 2.0.0 + celery 4.x 的兼容性问题,于是选择使用 pyamqp 协议而不是使用默认的 amqp 协议,具体操作就是将 broker_url 改为如下格式:
broker_url = pyamqp://cord:123456@10.55.63.51:5672//
### transport://userid:password@hostname:port/virtual_host
而将 celery_result_backend 改为其他实现,比如 mysql:
celery_result_backend = db+mysql://af:123456@10.55.63.51/airflow
至此问题解决。
总结:
在排查问题的时候需要针对问题深入排查,而不是无根据的臆测,要针对提示去逐步排查,而不是一味无目的去尝试。
虽然该问题已解决,但是推测应该是缺失相关配置导致了这个问题,但是我加上了优先级相关的配置并不起作用,所以暂时通过修改源码修复这个问题。
c# typeof 与 Type.GetType 使用与效率对比
static void ReflectionTest()
{//测试两种反射的效率问题
//Type.GetType()只能在同一个程序集中使用,typeof则可以跨程序集(assembly)
//通过下面的实测,发现typeof是比GetType快40多倍
var timer = Stopwatch.StartNew();
timer.Start();
Type tx = Type.GetType("string");
var tx1 = Type.GetType("float");
timer.Stop();
Console.WriteLine("T1= " + timer.Elapsed);//0.0000471
timer.Restart();
tx = typeof(string);
tx1 = typeof(float);
timer.Stop();
Console.WriteLine("T2= " + timer.Elapsed);//0.0000011
}
com.sun.tools.classfile.Type.TypeParamType的实例源码
public StringBuilder visitTypeParamType(TypeParamType type,StringBuilder sb) { sb.append(type.name); String sep = " extends "; if (type.classBound != null && (options.verbose || !type.classBound.isObject())) { sb.append(sep); append(sb,type.classBound); sep = " & "; } if (type.interfaceBounds != null) { for (Type bound: type.interfaceBounds) { sb.append(sep); append(sb,bound); sep = " & "; } } return sb; }
@Override public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public StringBuilder visitTypeParamType(TypeParamType type,bound); sep = " & "; } } return sb; }
public String visitTypeParamType(TypeParamType type,Void p) { StringBuilder sb = new StringBuilder(); sb.append("TA{"); sb.append(type.name); if (type.classBound != null) { sb.append(":c"); sb.append(print(type.classBound)); } if (type.interfaceBounds != null) sb.append(print(":i",type.interfaceBounds,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
public String visitTypeParamType(TypeParamType type,"")); sb.append("}"); return sb.toString(); }
String printTypeArgs(List<? extends TypeParamType> typeParamTypes) { StringBuilder builder = new StringBuilder(); appendIfNotEmpty(builder,"<",typeParamTypes,"> "); return builder.toString(); }
public Void visitTypeParamType(TypeParamType type,Void p) { findDependencies(type.classBound); findDependencies(type.interfaceBounds); return null; }
String printTypeArgs(List<? extends TypeParamType> typeParamTypes) { StringBuilder builder = new StringBuilder(); appendIfNotEmpty(builder,"> "); return builder.toString(); }
public Void visitTypeParamType(TypeParamType type,Void p) { findDependencies(type.classBound); findDependencies(type.interfaceBounds); return null; }
String printTypeArgs(List<? extends TypeParamType> typeParamTypes) { StringBuilder builder = new StringBuilder(); appendIfNotEmpty(builder,"> "); return builder.toString(); }
public Void visitTypeParamType(TypeParamType type,Void p) { findDependencies(type.classBound); findDependencies(type.interfaceBounds); return null; }
String printTypeArgs(List<? extends TypeParamType> typeParamTypes) { StringBuilder builder = new StringBuilder(); appendIfNotEmpty(builder,"> "); return builder.toString(); }
public Void visitTypeParamType(TypeParamType type,Void p) { findDependencies(type.classBound); findDependencies(type.interfaceBounds); return null; }
String printTypeArgs(List<? extends TypeParamType> typeParamTypes) { StringBuilder builder = new StringBuilder(); appendIfNotEmpty(builder,"> "); return builder.toString(); }
public Void visitTypeParamType(TypeParamType type,Void p) { findDependencies(type.classBound); findDependencies(type.interfaceBounds); return null; }
String printTypeArgs(List<? extends TypeParamType> typeParamTypes) { StringBuilder builder = new StringBuilder(); appendIfNotEmpty(builder,"> "); return builder.toString(); }
public Void visitTypeParamType(TypeParamType type,Void p) { findDependencies(type.classBound); findDependencies(type.interfaceBounds); return null; }
public Void visitTypeParamType(TypeParamType type,Void p) { findDependencies(type.classBound); findDependencies(type.interfaceBounds); return null; }
String printTypeArgs(List<? extends TypeParamType> typeParamTypes) { StringBuilder builder = new StringBuilder(); appendIfNotEmpty(builder,"> "); return builder.toString(); }
public Void visitTypeParamType(TypeParamType type,Void p) { findDependencies(type.classBound); findDependencies(type.interfaceBounds); return null; }
public Void visitTypeParamType(TypeParamType type,Void p) { findDependencies(type.classBound); findDependencies(type.interfaceBounds); return null; }
Django TypeError: isinstance() arg 2 must be a type or tuple of types
报错:
TypeError: isinstance() arg 2 must be a type or tuple of types
from django.db import models
from django.contrib.auth.models import AbstractUser
from blog.models import Blog
class UserInfo(AbstractUser):
# identifier = models.CharField(max_length=40, unique=True)
# USERNAME_FIELD = ''identifier''
nid = models.AutoField(primary_key=True)
# 手机号
telephone = models.CharField(max_length=32)
# 用户头像
avatar = models.FileField(upload_to=''avatar/'', default=''avatar/default.png'')
# # 用户创建时间
# create_date = models.DateTimeField(auto_now_add=True)
# # 用户博客--一对一对应博客表
blog = models.OneToOneField(to=Blog, to_field=''nid'', on_delete=models.CASCADE, null=True)
blog app
from django.db import models
# Create your models here.
class Blog(models.Model):
nid = models.AutoField(primary_key=True)
# 博客名称
title = models.CharField(max_length=32)
# 站点名称
site_name = models.CharField(max_length=32)
# 博客主题样式
theme = models.CharField(max_length=32)
当需要关联的表 不在同一个 py 文件下时
blog = models.OneToOneField(to="Blog", to_field=''nid'', on_delete=models.CASCADE, null=True)
这种写法是错误的, 因为django 无法当做一个模块来导入。所以会因为找不到 而报错。
但是所有class都在同一个py文件下,可以用“Blog” 这种方式导入
加引号 默认在当前文件里面找,
假如Blog在本py文件内 可以to=Blog 但是Blog类要写在这个表上面UserInfo。
今天关于Oracle基本知识:%TYPE 和 %ROWTYPE和oracle中type用法的分享就到这里,希望大家有所收获,若想了解更多关于Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查、c# typeof 与 Type.GetType 使用与效率对比、com.sun.tools.classfile.Type.TypeParamType的实例源码、Django TypeError: isinstance() arg 2 must be a type or tuple of types等相关知识,可以在本站进行查询。
本文标签: