FileTable file_stream column: "Cannot call methods on varbinary" - filetable

I'm trying to use file_stream.GetFileNamespacePath() as documented here:
https://learn.microsoft.com/en-us/sql/relational-databases/system-functions/getfilenamespacepath-transact-sql?view=sql-server-2017 using this code:
use StepwiseProcedures
declare #root varchar(100)
SELECT #root = FileTableRootPath();
declare #fullPath varchar(1000);
SELECT #fullPath = #root + Code_filetable.file_stream.GetFileNamespacePath() FROM Code_filetable
WHERE Name = '118.txt';
This code does not pass a syntax check and the message is:
"Cannot call method on varbinary"
The file_stream column is type varbinary(MAX) in the fixed schema enforced for every FileTable created. I've been using several FileTable's for more than a year and other operations are working as documented.
If I can't get GetFileNamespacePath() to work, I'll have to somehow hard-code the paths I seen in File Manager, or perhaps migrate to SQL Server 2016 or later.
Note that you must establish your database instance to support FILESTREAM etc. before you can create and use a FileTable and reproduce this issue. Configuration is described here:
https://learn.microsoft.com/en-us/sql/relational-databases/blob/enable-and-configure-filestream?view=sql-server-2017
I've read the following through the following links, but nothing comes close to addressing this issue.
https://learn.microsoft.com/en-us/sql/relational-databases/system-functions/getfilenamespacepath-transact-sql?view=sql-server-2017
SQL FileTable GetFileNamespacePath
https://www.sqlservercentral.com/Forums/Topic1715710-3077-1.aspx
https://sqltales.wordpress.com/2012/05/15/varbinary-vs-filestream-and-other-blob-issues-3/
https://www.databasejournal.com/features/mssql/filestream-and-filetable-in-sql-server-2012.html
https://svenaelterman.wordpress.com/2012/07/31/pathname-versus-getfilenamespacepath/
I'm using Microsoft SQL Server 2014 (Enterprise 64-bit)
Thanks

Related

OpenJpa2.0 How to map Oracle sys.XMLTYPE column to String

I changed Change in persistence.xml
I also changed column definition (columnDefinition="XDB.XMLType") for xml fields
I checked OpenJpa(http://openjpa.208410.n2.nabble.com/Oracle-XMLType-fetch-problems-td6208344.html) site and IBM (http://www.ibm.com/support/knowledgecenter/SS7J6S_7.5.0/com.ibm.wsadapters.jca.jdbc.doc/env/doc/rjdb_problemsolutions.html)
My env is OpenJpa 2.0 and WAS 7
its throwing exception
org.apache.openjpa.persistence.PersistenceException: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "SYS.XMLTYPE", line 169
Please suggest without changing OpenJpa2.0 as its part of IBM WebSphere Application Server V7.0 how can i handle sys.XMLTYPE data, i am migrating my application from db2 to Oracle in same environment.
Writing XML data can be tricky some times! Getting the correct drivers and things defined properly can have its challenges. I can not say exactly what you need to do given the lack of info on your domain model and such, but let me give some general things to look for. First, there is an XML test in the OpenJPA test framework if you want to make reference to it. It can be seen publicly here:
https://apache.googlesource.com/openjpa/+/refs/heads/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/
Or, another test using an "XMLValueHandler" (likely this is beyond the scope of what you are looking for):
https://apache.googlesource.com/openjpa/+/refs/heads/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/
Second, (stating the obvious) I assume you have a column in Oracle defined as "XMLTYPE". Also, I see you are using schema SYS. I'm sure you are aware but this is a system/admin schema......just for sanity sake you might want to first get things running using a non-system/admin schema just so we don't get hung up with any issues with your OpenJPA client not having the correct permissions.
Next, you need the following definition:
#Lob #Basic
#Column(name = "ANXMLCOLUMN", columnDefinition="XMLCOLUMN XMLType")
private String anXMLString;
The #Lob I think will be necessary if you are using data greater than 4000 chars (this was mentioned in one of the comments). To start I'd use a very small set of data (a couple characters), once that works, then experiment with > 4k.
Next, make sure to use the correct JDBC driver. The last time I experimented with an XMLType I used the Oracle JDBC 11.2.0.2 driver.
Finally, you might need to use the property "openjpa.jdbc.DBDictionary" with value "oracle(supportsSetClob=true,maxEmbeddedClobSize=-1)". Again, experiment with this AND look at the OpenJPA documentation on these properties to determine if they are necessary in your scenario. I think the supportsSetClob=true will only be necessary for older version (pre-2.2.x) of OpenJPA. You might also need to use property "openjpa.jdbc.SchemaFactory" with value "native". I would suggest you first try without either or these two properties. If that doesn't help, then experiment with these two properties. I know this is vague, but I don't know what your DDL or domain model looks like so I have to keep in vague.
Thanks,
Heath Thomann

File Exists and Exception Handling in U-Sql

Two questions
How to check file exists or not before EXTRACT?
we have scenario where new inputs file is generated every day for catalog data. we need to merge new input with d-1 file. before merge we what to make sure that new input file exists at source location
does u-sql supports try...catch block?
Regarding checking if a file exists. We recently released a compile-time IF statement that indeed can check for partition existence (and other objects such as files and tables are on the roadmap).
Once that feature is released (still one or two refreshs out at the time of this answer) it may look something like (syntax subject to change):
IF FILE.EXISTS("/mydir/myfile.csv") THEN
#data = EXTRACT ... FROM "/mydir/myfile.csv" USING ...;
...
#jobstate = SELECT * FROM (VALUES("job completed")) AS T(status);
ELSE
#jobstate = SELECT * FROM (VALUES("file not ready. Job not executed.")) AS T(status);
END;
OUTPUT #jobstate TO "/jobs/myjobstate.csv" USING Outputters.Csv();
You will be able to provide the name as a parameter as well. Please let me know if that will work for your scenario.
An other alternative is to use the file set syntax, especially if you want to use a dynamic value to determine the process. That would simply create an empty rowset:
#data = EXTRACT ..., date DateTime
FROM "/mydir/{date:yyyy}/{date:MM}/{date:dd}/data.csv"
USING ...;
#data = SELECT * FROM #data WHERE date == DateTime.Now.AddDays(-1);
... // continue processing #data that is empty if yesterday's file is not yet there
Having said that, you may want to check of your job orchestration framework (such as ADF) may be a better place to check for existence before submitting the job in the first place.
As to the try catch block: U-SQL itself is a script-level optimizable, declarative language where the plan gets generated and optimized at runtime over the whole script. Thus providing a dynamic TRY-CATCH is currently not available, since it would severely impact the ability to optimize the script (e.g., you cannot move predicates or column pruning outside of a try-catch block). Also TRY/CATCH can lead to some very hard to understand and debug code, especially if it is used to mimic procedural workflows in an otherwise declarative environment.
However, you can use try/catch inside your C# functions without problems if you need to catch C# runtime errors.
FILE.EXISTS() always returns True when executed locally. However, it works when executing against Azure Data Lake.
Tried MSDN example and the following returns True, True
DECLARE #filepath_good = "/Samples/Data/SearchLog.tsv";
DECLARE #filepath_bad = "/Samples/Data/zzz.tsv";
#result =
SELECT FILE.EXISTS(#filepath_good) AS exists_good,
FILE.EXISTS(#filepath_bad) AS exists_bad
FROM (VALUES (1)) AS T(dummy);
OUTPUT #result
TO "/Output/FileExists.txt"
USING Outputters.Csv();
I have Microsoft Azure Data Lake Tools for Visual Studio version 2.2.5000.0

SAP HANA custom dictionary: full-text-index not generated or updated

There are two problems with SAP HANA custom dictonaries.
Updating and recompiling the dictionary has no effect on the full-text-index table (even by dropping and generating the full-text-index again)
using custom dictionaries & configuration may lead to an empty fulltext-index-table
For the 1. Problem
deleting the configuration file and replace it with a new file (same content but different file name) then activating all changes (activates the deletion of the old config and adds the new config) seems to be a work-around.
Note: this means you also have to change the configuration name in the SQL command.
For the 2. Problem
Check this trace file:
/usr/sap/HDB/HDB00/hanadb/trace/preprocessor_alert_hanadb.trc
This error message:
File read Error '/usr/sap/HDB/SYS/global/hdb/custom/config/lexicon//EXTRACTION_CORE_MOD2', error='Storage object does not exist: $STORAGEOBJECT$'
occurs if the configuration file EXTRACTION_CORE_MOD2 is not properly activated in the repository under sap.hana.ta.config. So double check the repository if the configuration file exists in the specified path.
For the first problem, I have the same scenario in which I need to make some changes in the custom dictionary and activated it. It did not affect my index table unit I run the following statement:
ALTER INDEX MYINDEX REBUILD;
I have checked it and the changes affect the index table by this statement. So you do not have to remove your index or save the changes of your custom dictionary in a file with new name.

Can the Path assigned a SQLite DB be an arbitrary value?

In this blog post, some prerequisite code for getting started using SQLite in Windows Store Apps is given, for adding to the OnLaunched method of App.xaml.cs:
// Get a reference to the SQLite database
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "customers.sqlite");
My question is: Can I use any arbitrary value to replace the "customers.sqlite" part, or does it have to match something else in my code, such as the name of my table definition class (in my case "PhotraxCoreData.cs" which, according to Mr. Green's suggestion, I added below a newly-created "Models" folder)?
My understanding is that, once I've got those classes defined (I do), and the code above in App.xaml.cs, along with this there (adapted for my SQLite classes):
using (var db = new SQLite.SQLiteConnection(this.DBPath))
{
// Create the tables if they don't exist
db.CreateTable<PhotraxBaseData>();
db.CreateTable<PhotraxNames>();
db.CreateTable<PhotraxQueries>();
}
...SQLite tables based on those classes I specified will be created, and have the name "customers.sqlite" (provided I don't change it).
So, can I use:
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "platypus.sqlite");
...or must it be something like:
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "PhotraxCoreData.sqlite");
That database name is just a file name.
The directory must be accessible by your app, but the file name can be anything.
AS CL says, the file name can be anything the app has direct access to. Windows Store apps have limited access to the file system, so the sqlite database must be in either the apps install location (read only) or it's app data folder (read write). A common pattern is to ship a seed database in the app package and then copy it from the install location to app data on first use so it can be written to.

Using SQL Server 2012 Geography Data Type with ASP.Net - DataReader.GetFieldType(x) returned null

I've written an ASP.Net 4 Application which has been working perfectly. However, I decided to make use of the new Geography Data Type in Sql Sever 2012. This worked perfectly on my local machine but fails when I upload.
I get there error "DataReader.GetFieldType(9) returned null." when doing a usual "select * FROM Table" query on a table that contains one of these datatypes.
I have searched the various threads regarding adding a reference to the Microsoft.SqlServer.Types.dll into my project and changing Copy Local to true. However I am getting the same error.
I run the database and the web server on two separate servers so I don't think there are any assemblies on the web server unless I upload them with my project.
Am I missing any other assemblies that are needed? or any other settings?
I've taken days trying to solve this and uploading variouse libraries. Any help would be appreciated.
msdn
When the compatibility level is 100 or below in SQL Server 2012 then the geography data type has the following restrictions:
•Each geography instance must fit inside a single hemisphere. No spatial objects larger than a hemisphere can be stored.
•Any geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) or Well-Known Binary (WKB) representation that produces an object larger than a hemisphere throws an ArgumentException.
•The geography data type methods that require the input of two geography instances, such as STIntersection(), STUnion(), STDifference(), and STSymDifference(), will return null if the results from the methods do not fit inside a single hemisphere. STBuffer() will also return null if the output exceeds a single hemisphere.
From what I can tell you will at least need SQL Server installed locally when you initially add the reference. If you can I would try and install SQL Express locally first (you do not need to use it just install it) and then try your code again to see if that is the problem.
References:
DataReader.GetFieldType returned null
http://blogs.bing.com/maps/2013/08/05/advance-spatial-queries-using-entity-framework-5/
Edit:
I am more familiar with using spatial types via the entity framework. It seems if you want to use them directly you need to use a nuget package in order to get the required DLLs into the project. From the Microsoft ADO.NET blog page
SqlServerSpatial110.dll – This is a native assembly so it cannot be added as a project reference.
References:
Microsoft ADO.NET Blog
http://blogs.msdn.com/b/adonet/archive/2013/12/09/microsoft-sqlserver-types-nuget-package-spatial-on-azure.aspx
Relevant SO Questions
'Microsoft.SqlServer.Types' version 10 or higher could not be found on Azure
https://gis.stackexchange.com/questions/382/how-can-i-use-sql-servers-spatial-types-from-a-net-application
Spent heaps of time on this, adding references as well, but I found a workaround i want to share.
Should work fine on asp.net as well.
I use the following query to parse me the string representation of the object:
DECLARE #result geography;
SELECT #result = area FROM news WHERE id LIKE #id ;
SELECT ..., #result.STAsText() as area FROM news WHERE id LIKE #id;
And in the asmx (c#) webservice i retrieved my SQLGeography with a parser method:
row["area"].ToString()
After that you can use a parser method to retrieve the SQLGeography object.
/// <summary>
/// Converts a String into an sql geography object.</summary>
/// <param name="pText">The string representation of the sql geography object. </param>
public static SqlGeography GetGeographyFromText(String pText)
{
SqlString ss = new SqlString(pText);
SqlChars sc = new SqlChars(ss);
try
{
if (pText.Contains("POINT"))
{
return SqlGeography.STPointFromText(sc, 4326);
}
return SqlGeography.STPolyFromText(sc, 4326);
}
catch (Exception ex)
{
return SqlGeography.STMPolyFromText(sc, 4326);
throw ex;
}
}
Hope it helps anyone!
In the end I couldn't get it to work as it does on my development machine and I don't want to install Visual Studio or SQL Server Express on the web server so instead I just removed all the queries where I did "SELECT * FROM Table" and the error went away. It still let me do my calculations using the geography field, but doesn't like you trying to show it on the screen. Thanks for all your help!

Resources