How can i write a string/query to a hive query file in cmd? - cmd

i have ran the below so i can write this to a file settings.hql
"SET schema = products;SET company = amazon;SET tablename = test;" > settings.hql
in cmd.
but it does not work i get:
SET schema = products;SET company = amazon;SET tablename = test;: command not found

Use echo command:
C:\Users\leftjoin>echo SET schema = products;SETcompany = amazon;SET tablename = test; > settings.hql
C:\Users\leftjoin>type settings.hql
SET schema = products;SETcompany = amazon;SET tablename = test;

If you are using Microsoft Windows cmd.exe as your tag implies, you need to use ECHO.
ECHO>"settings.hql" SET schema = products;SET company = amazon;SET tablename = test;

Related

Surreal DB - Query from Sets

I have created an author user in surreal DB like this:
CREATE author:shivam SET
name.first = 'Shivam',
name.last = 'Sahil',
name.full = string::join(' ', name.first, name.last),
age = 23,
admin = true,
signup_at = time::now()
;
Now I want to query all the authors, but when I do:
SELECT * FROM author;
I get 0 results.
Is it supposed to be queried in some other way?
What you did should work well as you can see here
Don't forget to start your server with something like this for example
surreal start --log info --user root --pass root memory
and log-in as in my above screenshot with:
surreal sql --conn http://localhost:8000 --ns yoloswag --db compabie
Then, your create query and select should work well!
Alternatively, you can give a try to that video or documentation's quick start.
Creating another author like this is properly fetched afterwards.
CREATE author:123 SET
name.first = 'bob',
name.last = 'hoh',
name.full = string::join(' ', name.first, name.last),
age = 30,
admin = false,
signup_at = time::now()
;
Don't forget that 123 is supposed to be a unique ID (a string should be fine tho).

KAFKA JDBC Source connector adds the default schema

I use the KAFKA JDBC Source connector to read from the database ClickHouse (driver - clickhouse-jdbc-0.2.4.jar) with incrementing mod.
Settings:
batch.max.rows = 100
catalog.pattern = null
connection.attempts = 3
connection.backoff.ms = 10000
connection.password = [hidden]
connection.url = jdbc:clickhouse://<ip>:8123/<schema>
connection.user = user
db.timezone =
dialect.name =
incrementing.column.name = id
mode = incrementing
numeric.mapping = null
numeric.precision.mapping = false
poll.interval.ms = 5000
query =
query.suffix =
quote.sql.identifiers = never
schema.pattern = null
table.blacklist = []
table.poll.interval.ms = 60000
table.types = [TABLE]
table.whitelist = [<table_name>]
tables = [default.<schema>.<table_name>]
timestamp.column.name = []
timestamp.delay.interval.ms = 0
timestamp.initial = null
topic.prefix = staging-
validate.non.null = false
Why does the connector additionally substitute the default scheme? and how to avoid it?
Instead of a request
SELECT * FROM <schema>.<table_name> WHERE <schema>.<table_name>.id > ? ORDER BY <schema>.<table_name>.id ASC
I get an error with
SELECT * FROM default.<schema>.<table_name> WHERE default.<schema>.<table_name>.id > ? ORDER BY default.<schema>.<table_name>.id ASC
You can create CH data source object like below (Where schema name is not passed).
final ClickHouseDataSource dataSource = new ClickHouseDataSource(
"jdbc:clickhouse://"+host+"/"+user+"?option1=one%20two&option2=y");
Then in SQL query, you can specify a schema name(schema.table). So it will not add the default schema in your query.

Query returns only 4 out of 12 values of my table. Why is this happening?

I have created a script which I am using on 2 different system. One is Windows 10 with SQL Server Express 2019 and the other is on Windows 7 (32bit) with SQL Server Express 2014. The db I am using has the same structure. The code I am using in ASP Classic is exactly the same on both machines! But in the win7 machine does not work as it should!
I am having a query to my db and the problem is that SOME of the values I am getting are empty. The code I am using is the following:
<%
Set rs21 = Server.CreateObject("ADODB.Recordset")
strSQL21 = "SELECT * FROM otherfiles WHERE animalid LIKE '" & lngRecordNo & "'
AND historyid LIKE '" & historyid & "' order by datedone DESC"
rs21.Open strSQL21, adoCon
%>
BLAH BLAH BLAH
<%
Do While not rs21.EOF
historyid = rs21("historyid")
if not historyid = "" then
Set rshis = Server.CreateObject("ADODB.Recordset")
strSQLhis = "SELECT * FROM history WHERE id_no LIKE '" & historyid & "' order by id_no DESC"
rshis.Open strSQLhis, adoCon
'------------------- if I remove the following line (Set rscol) it works fine ---------------------------
Set rscol = Server.CreateObject("ADODB.Recordset")
strcol = "SELECT * FROM hospitals WHERE id_no = "& rsGuestbook21("hosid") &" order by id_no DESC"
rscol.Open strcol, adocon
color = rscol("color")
%>
BLAH BLAH BLAH
<%=rs21("datedone")%> ---> empty value
<%=rs21("id_no")%> ---> works fine!!!
I am 100% sure that my table has its values. In fact as I mention above only but setting the rscol = Server.CreateObject("ADODB.Recordset") then the values becomes ??empty??. Commenting this line works fine.
I just figured out my ??mistake??...
Not really sure if it is a mistake thou... but the problem solved when I placed a field that had a DATA TYPE of "nvarchar(MAX)" at the end of my of my table! Weird stuff??? Do you think that there is something more than that in which I should investigate?

Invalid character - dollar sign for input param not decoded

I am facing an issue with some SQL scripts where I use parameter passing.
I call a script like this:
DEFINE sowner = "SOWNER"
DEFINE auser = "AUSER"
DEFINE tbsp = "TAB"
DEFINE insp = "IND"
#R1/do_your_job.sql $owner $auser $tbsp $insp
And inside R1/do_your_job :
define sowner = $1
define auser = $2
define tbsp = $3
define insp = $4
alter session set current_schema=$sowner;
And I get: Ora 00911: invalid character marking my $ sign
Why is it not decoding $sowner to "SOWNER"?
My file is marked with "set define $" anyway...
Thank you.
Use '&variable' while passing and '&1', '&2' etc while reading.
DEFINE sowner = "SOWNER"
DEFINE auser = "AUSER"
DEFINE tbsp = "TAB"
DEFINE insp = "IND"
#R1/do_your_job.sql &sowner &auser &tbsp &insp
Your do_your_job.sql may use it as
select '&1','&2','&3','&4' from dual;
Result
#R1/do_your_job.sql &sowner &auser &tbsp &inspSQL> SQL> SQL> SQL> SQL>
old 1: select '&1','&2','&3','&4' from dual
new 1: select 'SOWNER','AUSER','TAB','IND' from dual
'SOWNE 'AUSE 'TA 'IN
------ ----- --- ---
SOWNER AUSER TAB IND

VBS - Find SCCM Collection Id's, Names and Package Names a computer is apart of?

Currently I have 'excel SQL query' for subject requirement and it is executing fine without any issues.
Current Excel SQL query Script: I have created SQL query which is connect to SCCM server and get the below details.
Excel 2013/2016-> Data -> Connections-> Workbook Connections->
Excel SQL Query
Connection String:
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=CM_CAS;Data Source=<SCCMServerIP>;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=<SCCMServerHostName>;Use Encryption for Data=False;Tag with column collation when possible=False
Command Type: SQL
Command Text:
DECLARE #machname varchar(max)
SET #machname = '<DeviceHostName>'
select CollectionID,CollectionName,packagename,#machname as MachineName from v_AdvertisementInfo
-- select AssignmentID,AssignmentName,CollectionID,CollectionName,ApplicationName,AppModelID from v_ApplicationAssignment
where CollectionID in
(select FCM.CollectionId from dbo.v_R_System r join
dbo.v_FullCollectionMembership FCM on R.ResourceID = FCM.ResourceID join
dbo.v_Collection C on C.CollectionID = FCM.CollectionID Where R.Name0
= #machname) and
ProgramName not like '%Remove%'and
ProgramName not like '%Un-Install%'and
CollectionName not like '%Test%' and
CollectionName not like '%temp%'
union
select CollectionID,CollectionName,ApplicationName,#machname as MachineName from v_ApplicationAssignment
where CollectionID in
(select FCM.CollectionId from dbo.v_R_System r join
dbo.v_FullCollectionMembership FCM on R.ResourceID = FCM.ResourceID join
dbo.v_Collection C on C.CollectionID = FCM.CollectionID Where R.Name0
= #machname) and
CollectionName not like '%Test%' and
CollectionName not like '%temp%'
+++++++++++++++++++++++++++++++++++++++++++++
And example Excel output will be as below for
hostname 'IN-00001236'
Result/Output
Requirement is : for Laptop EOL refresh
Gather all collection id's which is member of IN-00001236 (EOL Device) and add new device host name (IN-1111) into result collection id's! then delete IN-00001236 from SCCM. Generate report in excel/CSV?
I have a challenge In above Excel SQL Query? like I have add/replace hostname every time/run under 'Command Text'
So, I need to automate this complete process using VBS or PS?
If I understand you correctly you want a new record to have all memberships of the old record.
In my opinion you can focus only on collection memberships, whether the deployment to a collection is a package, application or update should not be important as long as the collections are the same.
So first you would need to translate your devices name to a resourceid as those are the primary key in all sccm tables:
$WS = 'IN-00001236'
$resourceID = (Get-WmiObject -Class "SMS_R_System" -Filter "(Name = '$WS')" | Select-Object -last 1).ResourceID
once you have that you can get all the collection members
$collectionMembers = (Get-WmiObject -Class "SMS_FullCollectionMembership" -Filter "(ResourceID = '$resourceID')" | where { $_.IsDirect -eq $true }).CollectionID
to delete a record use this
[void](Get-WmiObject -Class "SMS_R_System" -Filter "(ResourceID = '$resourceID')").Delete()
now you have to add those to the new record (first get resourceID again)
Foreach($CollID in $collectionMembers) {
$CollectionQuery = Get-WmiObject -Class "SMS_Collection" -Filter "CollectionID = '$CollID'"
$directRule = (Get-WmiObject -List -Class "SMS_CollectionRuleDirect").CreateInstance()
$directRule.ResourceClassName = "SMS_R_System"
$directRule.ResourceID = $newResourceID
[void]$CollectionQuery.AddMemberShipRule($directRule)
}
If you want to use this for multiple devices in a loop you can just create a csv file with oldrecord,newrecord
import with
$records = Import-Csv <path to csv> -Header old,new
and then use a loop outside all the code like
foreach ($record in $records) {
# inside here use $record.old or $record.new for the old/new names like
# $WS = $record.old
}
Now i don't know if you even would need the excel file anymore if you just have a script doing the work, but in case you really do you can create a excel readable csv from powershell with export-csv (might need options like -Delimiter ';' -NoTypeInformation -Encoding UTF8 to be easily readable)
In theory you can execute your whole sql query in powershell as well
$sqlText = "your query"
$SQLConnection = new-object System.Data.SqlClient.SQLConnection("Server=<sccmserver>;Database=<sccm db>;Integrated Security=SSPI")
$SQLConnection.Open();
$cmd = new-object System.Data.SqlClient.SqlCommand($sqlText, $SQLConnection);
$reader = $cmd.ExecuteReader()
while ($reader.Read()) {
$reader["<columnname>"]
}
and recreate your file in the ps script
Finally I completed VBS as below. it's working fine.
Dim connect, sql, resultSet, pth, txt
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set connect = CreateObject("ADODB.Connection")
connect.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=CM_CAS;Data Source=<SCCMServerIP>;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=<SCCMServerHostName>;Use Encryption for Data=False;Tag with column collation when possible=False;Trusted_Connection=True;"
connect.Open
sql="select CollectionID,CollectionName,packagename,<HostName> as MachineName from v_AdvertisementInfo where CollectionID in (select FCM.CollectionId from dbo.v_R_System r join dbo.v_FullCollectionMembership FCM on R.ResourceID = FCM.ResourceID join dbo.v_Collection C on C.CollectionID = FCM.CollectionID Where R.Name0 = 'HostName') and ProgramName not like '%Remove%'and ProgramName not like '%Un-Install%'and CollectionName not like '%Test%' and CollectionName not like '%temp%' union select CollectionID,CollectionName,ApplicationName,#machname as MachineName from v_ApplicationAssignment where CollectionID in (select FCM.CollectionId from dbo.v_R_System r join dbo.v_FullCollectionMembership FCM on R.ResourceID = FCM.ResourceID join dbo.v_Collection C on C.CollectionID = FCM.CollectionID Where R.Name0 = 'HostName') and CollectionName not like '%Test%' and CollectionName not like '%temp%'"
Set resultSet = connect.Execute(sql)
pth = "C:\test\test.csv"
Set txt = ObjFSO.CreateTextFile(pth, True)
On Error Resume Next
resultSet.MoveFirst
Do While Not resultSet.eof
txt.WriteLine(resultSet(0) & "," & resultSet(1) & "," & resultSet(2))
resultSet.MoveNext
Loop
resultSet.Close
connect.Close
Set connect = Nothing

Resources